Candy.Updater.CandyUpdater.UpdateFilesAsync C# (CSharp) Method

UpdateFilesAsync() private static method

private static UpdateFilesAsync ( ZipArchive archive, string targetDirectoryPath ) : System.Threading.Tasks.Task
archive System.IO.Compression.ZipArchive
targetDirectoryPath string
return System.Threading.Tasks.Task
        private static async Task UpdateFilesAsync(ZipArchive archive, string targetDirectoryPath)
        {
            // Length > 0 でファイル(非フォルダ)にしぼる(で正しいのか?)
            foreach (var entry in archive.Entries.Where(x => x.Length > 0))
            {
                var destPath = Path.Combine(targetDirectoryPath, entry.FullName);

                // 自分自身の場合は確実に書き込み失敗するため無視する(現状は Candy.exe 側で書き換えてもらう想定。将来的には自身で自身をアップデートできるようにしたい=シャルロッテ方式)
                if (String.Equals(Assembly.GetEntryAssembly().Location, destPath)) continue;

                var destFile = new FileInfo(destPath);
                var destDir = new DirectoryInfo(Path.GetDirectoryName(destPath));

                // 上書き先のディレクトリが存在しない場合は作成しておかないと File.OpenWrite で例外になる
                if (!destDir.Exists)
                {
                    destDir.Create();
                }

                if (destFile.Exists)
                {
                    if (destFile.Attributes.HasFlag(FileAttributes.ReadOnly))
                    {
                        destFile.Attributes = destFile.Attributes & ~FileAttributes.ReadOnly;
                    }
                }

                using (var source = entry.Open())
                using (var dest = File.OpenWrite(destPath))
                {
                    dest.SetLength(0);
                    await source.CopyToAsync(dest).ConfigureAwait(false);
                }
            }
        }
        private static Task RemoveFilesAsync(IEnumerable<string> removeFiles, string applicationDirectory)

Same methods

CandyUpdater::UpdateFilesAsync ( FileInfo packageFile, string targetDirectoryPath ) : System.Threading.Tasks.Task