private async Task <bool> TryDownLoad(string url, string patchName) { WebClient wc = new WebClient(); FileScaner.MakeDir(TempFolder); if (url == null || patchName == null) { return(false); } LogAdd("Try DownLoad [" + url + " ]."); if (FileScaner.ChkFile(TempFolder + patchName)) { LogAdd("Archive Found. Skip Download."); } else { try { await wc.DownloadFileTaskAsync(new Uri(url), TempFolder + patchName); LogAdd("Download OK."); } catch (WebException we) { Debug.LogWarning("Error WebException : " + we.Status); FileScaner.RemoveFile(TempFolder + patchName); return(false); } } return(true); }
/// <summary> /// パッチをインストールします。インストール済みの場合スキップされ True が返されます。 /// </summary> public async Task <bool> InstallPatch(Patch target) { int tryCount = 0; TryAgain: if (!await TryDownLoad(target.Url, target.PatchName)) { if (!await TryDownLoad(target.SubUrl, target.PatchName)) { return(false); } } LogAdd("Try UnZip [" + target.PatchName + "]."); if (FileScaner.MakeDir(PatchFolder + target.PatchName)) { try { ZipFile.ExtractToDirectory(TempFolder + target.PatchName, PatchFolder + target.PatchName, Encoding.UTF8); LogAdd("UnZip OK."); } catch (Exception e) { Debug.LogWarning("Error Exception : " + e); return(false); } } else { int installedFileCount = FileScaner.GetCountInFolder(PatchFolder + target.PatchName); LogAdd("Skip unpack. Installed [" + installedFileCount + "] Files."); if (target.FileCount != 0 && target.FileCount != installedFileCount) // インストール済みの数が異なる { LogAdd("Different File Error. Correct [" + target.FileCount + "] Files. Try Again."); UnInstallPatch(target); if (tryCount == 0) { tryCount++; goto TryAgain; } else { return(false); } } } InstalledPatch.Add(target); return(true); }