/// <summary> /// Updates any translation files that differ from that found online. /// </summary> /// <param name="BaseTranslationURL">String URL folder that contains all the translation XML files.</param> /// <param name="Culture">Language version to download</param> /// <param name="TranslationsRef">Link to the translation engine to obtain current translation versions.</param> /// <returns>Returns a state code depending on how it ran. [-1: Error, 0: Nothing to update, 1: Update Successful]</returns> public int UpdateTranslations(string BaseTranslationURL, Translations TranslationsRef) { using (WebClient Client = new WebClient()) { int ReturnValue = 0; string MainFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); try { if (!Directory.Exists(Path.Combine(MainFolder, "XMLs"))) { Directory.CreateDirectory(Path.Combine(MainFolder, "XMLs")); } if (!Directory.Exists(Path.Combine(MainFolder, "XMLs", "tmp"))) { Directory.CreateDirectory(Path.Combine(MainFolder, "XMLs", "tmp")); } if (!Directory.Exists(Path.Combine(MainFolder, "XMLs", "Old"))) { Directory.CreateDirectory(Path.Combine(MainFolder, "XMLs", "Old")); } // In every one of these we download it to a temp folder, check if the file works, then move it over. if (IsOnlineVersionGreater(TranslationType.PartTranslate, TranslationsRef.JPTRsVersion)) { Client.DownloadFile(BaseTranslationURL + "JPTRs.xml", Path.Combine(MainFolder, "XMLs", "tmp", "JPTRs.xml")); ReturnValue = XmlFileWizard(MainFolder, "JPTRs.xml", TranslationType.PartTranslate); } if (IsOnlineVersionGreater(TranslationType.SkillDetails, TranslationsRef.SkillListVersion)) { Client.DownloadFile(BaseTranslationURL + "SkillList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "SkillList.xml")); ReturnValue = XmlFileWizard(MainFolder, "SkillList.xml", TranslationType.SkillDetails); } if (IsOnlineVersionGreater(TranslationType.WeaponList, TranslationsRef.WeaponListVersion)) { Client.DownloadFile(BaseTranslationURL + "WeaponList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "WeaponList.xml")); ReturnValue = XmlFileWizard(MainFolder, "WeaponList.xml", TranslationType.WeaponList); } if (IsOnlineVersionGreater(TranslationType.TenTreasure, TranslationsRef.TenListVersion)) { Client.DownloadFile(BaseTranslationURL + "TenList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "TenList.xml")); ReturnValue = XmlFileWizard(MainFolder, "TenList.xml", TranslationType.TenTreasure); } if (IsOnlineVersionGreater(TranslationType.BulletMake, TranslationsRef.BulletListVersion)) { Client.DownloadFile(BaseTranslationURL + "BulletList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "BulletList.xml")); ReturnValue = XmlFileWizard(MainFolder, "BulletList.xml", TranslationType.BulletMake); } if (IsOnlineVersionGreater(TranslationType.ItemIdx, TranslationsRef.BulletListVersion)) { Client.DownloadFile(BaseTranslationURL + "ItemList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "ItemList.xml")); ReturnValue = XmlFileWizard(MainFolder, "ItemList.xml", TranslationType.ItemIdx); } } catch { // Failed to download files. return(-1); } if (Directory.Exists(Path.Combine(MainFolder, "XMLs", "tmp"))) { Directory.Delete(Path.Combine(MainFolder, "XMLs", "tmp"), true); } return(ReturnValue); } }
/// <summary> /// Updates any translation files that differ from that found online. /// </summary> /// <param name="BaseTranslationURL">String URL folder that contains all the translation XML files.</param> /// <param name="Culture">Language version to download</param> /// <param name="TranslationsRef">Link to the translation engine to obtain current translation versions.</param> /// <returns>Returns a state code depending on how it ran. [-1: Error, 0: Nothing to update, 1: Update Successful]</returns> public int UpdateTranslations(string BaseTranslationURL, Translations TranslationsRef) { using (WebClient Client = new WebClient()) { int ReturnValue = 0; string MainFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); try { if (!Directory.Exists(Path.Combine(MainFolder, "XMLs"))) Directory.CreateDirectory(Path.Combine(MainFolder, "XMLs")); if (!Directory.Exists(Path.Combine(MainFolder, "XMLs", "tmp"))) Directory.CreateDirectory(Path.Combine(MainFolder, "XMLs", "tmp")); if (!Directory.Exists(Path.Combine(MainFolder, "XMLs", "Old"))) Directory.CreateDirectory(Path.Combine(MainFolder, "XMLs", "Old")); // In every one of these we download it to a temp folder, check if the file works, then move it over. if (IsOnlineVersionGreater(TranslationType.PartTranslate, TranslationsRef.JPTRsVersion)) { Client.DownloadFile(BaseTranslationURL + "JPTRs.xml", Path.Combine(MainFolder, "XMLs", "tmp", "JPTRs.xml")); ReturnValue = XmlFileWizard(MainFolder, "JPTRs.xml", TranslationType.PartTranslate); } if (IsOnlineVersionGreater(TranslationType.SkillDetails, TranslationsRef.SkillListVersion)) { Client.DownloadFile(BaseTranslationURL + "SkillList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "SkillList.xml")); ReturnValue = XmlFileWizard(MainFolder, "SkillList.xml", TranslationType.SkillDetails); } if (IsOnlineVersionGreater(TranslationType.WeaponList, TranslationsRef.WeaponListVersion)) { Client.DownloadFile(BaseTranslationURL + "WeaponList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "WeaponList.xml")); ReturnValue = XmlFileWizard(MainFolder, "WeaponList.xml", TranslationType.WeaponList); } if (IsOnlineVersionGreater(TranslationType.TenTreasure, TranslationsRef.TenListVersion)) { Client.DownloadFile(BaseTranslationURL + "TenList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "TenList.xml")); ReturnValue = XmlFileWizard(MainFolder, "TenList.xml", TranslationType.TenTreasure); } if (IsOnlineVersionGreater(TranslationType.BulletMake, TranslationsRef.BulletListVersion)) { Client.DownloadFile(BaseTranslationURL + "BulletList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "BulletList.xml")); ReturnValue = XmlFileWizard(MainFolder, "BulletList.xml", TranslationType.BulletMake); } if (IsOnlineVersionGreater(TranslationType.ItemIdx, TranslationsRef.BulletListVersion)) { Client.DownloadFile(BaseTranslationURL + "ItemList.xml", Path.Combine(MainFolder, "XMLs", "tmp", "ItemList.xml")); ReturnValue = XmlFileWizard(MainFolder, "ItemList.xml", TranslationType.ItemIdx); } } catch { // Failed to download files. return -1; } if (Directory.Exists(Path.Combine(MainFolder, "XMLs", "tmp"))) Directory.Delete(Path.Combine(MainFolder, "XMLs", "tmp"), true); return ReturnValue; } }