/// <summary> /// Loads the Build, CDN and Patch configs /// </summary> /// <param name="directory"></param> /// <param name="locale"></param> private void LoadConfigs(string directory) { if (VersionsFile == null || CDNsFile == null) { throw new Exception("Versions and CDNs files must be loaded first"); } if (!VersionsFile.HasLocale(Locale)) { throw new Exception($"Versions missing {Locale} locale"); } if (BuildConfigMD5.Value != null) { BuildConfig = new KeyValueConfig(BuildConfigMD5.ToString(), directory, ConfigType.BuildConfig); } if (CDNConfigMD5.Value != null) { CDNConfig = new KeyValueConfig(CDNConfigMD5.ToString(), directory, ConfigType.CDNConfig); } // optionally load the patch config if (PatchConfigMD5.Value != null) { string path = Helpers.GetCDNPath(PatchConfigMD5.ToString(), "config", directory); if (File.Exists(path)) { PatchConfig = new KeyValueConfig(PatchConfigMD5.ToString(), directory, ConfigType.PatchConfig); } } }
/// <summary> /// Loads the Build, CDN and Patch configs /// </summary> /// <param name="directory"></param> /// <param name="locale"></param> private void LoadConfigs(string directory) { if (VersionsFile == null || CDNsFile == null) { throw new Exception("Versions and CDNs files must be loaded first"); } if (!VersionsFile.HasLocale(Locale)) { throw new Exception($"Versions missing {Locale} locale"); } if (!BuildConfigMD5.IsEmpty) { BuildConfig = new KeyValueConfig(BuildConfigMD5.ToString(), directory, ConfigType.BuildConfig); } if (!CDNConfigMD5.IsEmpty) { CDNConfig = new KeyValueConfig(CDNConfigMD5.ToString(), directory, ConfigType.CDNConfig); } if (!PatchConfigMD5.IsEmpty) { PatchConfig = new KeyValueConfig(PatchConfigMD5.ToString(), directory, ConfigType.PatchConfig); } }
/// <summary> /// Saves the configs using to the Blizzard standard location /// </summary> /// <param name="directory"></param> public void Save(string directory) { // save the localised configs BuildConfig.Write(directory); CDNConfig.Write(directory); // update the hashes VersionsFile.SetValue("buildconfig", BuildConfig.Checksum.ToString()); VersionsFile.SetValue("cdnconfig", CDNConfig.Checksum.ToString()); // save the primary configs CDNsFile.Write(directory, Product); VersionsFile.Write(directory, Product); }
/// <summary> /// Saves the configs using to the Blizzard standard location /// </summary> /// <param name="directory"></param> public void Save(string directory) { // save and update patch config value if (PatchConfig != null) { PatchConfig?.Write(directory); BuildConfig?.SetValue("patch-config", PatchConfig.Checksum.ToString()); } // save the localised configs BuildConfig?.Write(directory); CDNConfig?.Write(directory); // update the hashes VersionsFile.SetValue("buildconfig", BuildConfig.Checksum.ToString()); VersionsFile.SetValue("cdnconfig", CDNConfig.Checksum.ToString()); // save the primary configs CDNsFile.Write(directory, Product); VersionsFile.Write(directory, Product); }
/// <summary> /// Start updating. Use events to get informations. /// </summary> public void Start() { try { IVersionParser verPar; if (Path.GetExtension(VersionsFile.ToString()) == ".txt") { verPar = new VersionParserTxt(); } /*else if (Path.GetExtension(VersionsFile.ToString()) == ".xml") * { * verPar = new VersionParserXml(); * }*/ else { throw new InvalidOperationException("Cannot parse this type of version file."); } List <UpdateFile> availableVersions = verPar.GetMissingVersions(VersionsFile, CurrentVersion); foreach (var ver in availableVersions) { OnInformation(new InformationEventArgs("Available version: " + ver.Version.ToString())); } List <string> downloadedFiles = new List <string>(); IDownloadManager dowMan = new DownloadManager() { Destination = OwnerOrDirectoryPath }; dowMan.DownloadCompleted += (sender, args) => OnInformation(new InformationEventArgs("Downloaded and saved to: " + args.PathToFileOnComputer)); dowMan.DownloadCompleted += (sender, args) => downloadedFiles.Add(args.PathToFileOnComputer); dowMan.DownloadFiles(availableVersions); while (availableVersions.Count != downloadedFiles.Count) { Thread.Sleep(250); } downloadedFiles.Sort(); var extractor = new Extract.ExtractorZip() { Destination = OwnerOrDirectoryPath }; foreach (var downloadedFile in downloadedFiles) { extractor.Extract(downloadedFile); OnInformation(new InformationEventArgs("Extracted file: " + Path.GetFileName(downloadedFile))); } } catch (Exception e) { OnFailure(new ErrorEventArgs(e)); } finally { removeTemporaryFolder(); OnEnd(); } }