Grabacr07.KanColleWrapper.Updater.UpdateTranslations C# (CSharp) Method

UpdateTranslations() public method

Updates any translation files that differ from that found online.
public UpdateTranslations ( string BaseTranslationURL, string Culture, Translations TranslationsRef ) : int
BaseTranslationURL string String URL folder that contains all the translation XML files.
Culture string Language version to download
TranslationsRef Translations Link to the translation engine to obtain current translation versions.
return int
		public int UpdateTranslations(string BaseTranslationURL, string Culture, Translations TranslationsRef)
		{
			using (WebClient Client = new WebClient())
			{
				string CurrentCulture = (Culture == null || Culture == "en-US" || Culture == "ja-JP" || Culture == "en") ? "" : Culture;
				string CurrentCultureDir = (CurrentCulture != "" ? CurrentCulture + "\\" : "");
                string TranslationURL = (BaseTranslationURL.TrimEnd(new[] { '/' }) + "/" + CurrentCulture).TrimEnd(new[] { '/' }) + "/";
				XDocument TestXML;
				int ReturnValue = 0;

				try
				{
					if (!Directory.Exists("Translations")) Directory.CreateDirectory("Translations");
					if (!Directory.Exists("Translations\\" + CurrentCultureDir)) Directory.CreateDirectory("Translations\\" + CurrentCultureDir);
					if (!Directory.Exists("Translations\\tmp\\")) Directory.CreateDirectory("Translations\\tmp\\");

					// In every one of these we download it to a temp folder, check if the file works, then move it over.
					if (IsOnlineVersionGreater(TranslationType.Equipment, TranslationsRef.EquipmentVersion))
					{
						Client.DownloadFile(TranslationURL + "Equipment.xml", "Translations\\tmp\\Equipment.xml");

						try
						{
							TestXML = XDocument.Load("Translations\\tmp\\Equipment.xml");
							if (File.Exists("Translations\\" + CurrentCultureDir + "Equipment.xml")) 
								File.Delete("Translations\\" + CurrentCultureDir + "Equipment.xml");
							File.Move("Translations\\tmp\\Equipment.xml", "Translations\\" + CurrentCultureDir + "Equipment.xml");
							ReturnValue = 1;
						}
						catch (Exception ex)
						{
							Debug.WriteLine(ex);
							ReturnValue = -1;
						}
					}

					if (IsOnlineVersionGreater(TranslationType.Operations, TranslationsRef.OperationsVersion))
					{
						Client.DownloadFile(TranslationURL + "Operations.xml", "Translations\\tmp\\Operations.xml");

						try
						{
							TestXML = XDocument.Load("Translations\\tmp\\Operations.xml");
							if (File.Exists("Translations\\" + CurrentCultureDir + "Operations.xml"))
								File.Delete("Translations\\" + CurrentCultureDir + "Operations.xml");
							File.Move("Translations\\tmp\\Operations.xml", "Translations\\" + CurrentCultureDir + "Operations.xml");
							ReturnValue = 1;
						}
						catch (Exception ex)
						{
							Debug.WriteLine(ex);
							ReturnValue = -1;
						}
					}

					if (IsOnlineVersionGreater(TranslationType.Quests, TranslationsRef.QuestsVersion))
					{
						Client.DownloadFile(TranslationURL + "Quests.xml", "Translations\\tmp\\Quests.xml");

						try
						{
							TestXML = XDocument.Load("Translations\\tmp\\Quests.xml");
							if (File.Exists("Translations\\" + CurrentCultureDir + "Quests.xml"))
								File.Delete("Translations\\" + CurrentCultureDir + "Quests.xml");
							File.Move("Translations\\tmp\\Quests.xml", "Translations\\" + CurrentCultureDir + "Quests.xml");
							ReturnValue = 1;
						}
						catch (Exception ex)
						{
							Debug.WriteLine(ex);
							ReturnValue = -1;
						}
					}

					if (IsOnlineVersionGreater(TranslationType.Ships, TranslationsRef.ShipsVersion))
					{
						Client.DownloadFile(TranslationURL + "Ships.xml", "Translations\\tmp\\Ships.xml");

						try
						{
							TestXML = XDocument.Load("Translations\\tmp\\Ships.xml");
							if (File.Exists("Translations\\" + CurrentCultureDir + "Ships.xml"))
								File.Delete("Translations\\" + CurrentCultureDir + "Ships.xml");
							File.Move("Translations\\tmp\\Ships.xml", "Translations\\" + CurrentCultureDir + "Ships.xml");
							ReturnValue = 1;
						}
						catch (Exception ex)
						{
							Debug.WriteLine(ex);
							ReturnValue = -1;
						}
					}

					if (IsOnlineVersionGreater(TranslationType.ShipTypes, TranslationsRef.ShipTypesVersion))
					{
						Client.DownloadFile(TranslationURL + "ShipTypes.xml", "Translations\\tmp\\ShipTypes.xml");

						try
						{
							TestXML = XDocument.Load("Translations\\tmp\\ShipTypes.xml");
							if (File.Exists("Translations\\" + CurrentCultureDir + "ShipTypes.xml"))
								File.Delete("Translations\\" + CurrentCultureDir + "ShipTypes.xml");
							File.Move("Translations\\tmp\\ShipTypes.xml", "Translations\\" + CurrentCultureDir + "ShipTypes.xml");
							ReturnValue = 1;
						}
						catch (Exception ex)
						{
							Debug.WriteLine(ex);
							ReturnValue = -1;
						}
					}

				}
				catch (Exception ex)
				{
					// Failed to download files.
					Debug.WriteLine(ex);
					return -1;
				}

				if (Directory.Exists("Translations\\tmp\\")) Directory.Delete("Translations\\tmp\\");

				return ReturnValue;
			}
		}