private void UpdateInstalledTranslations() { try { Regex r = new Regex(@"\<TranslationVersion\>(\d+)\<\/TranslationVersion\>", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); List <string> lTranslationsInstalled = UrlUtil.GetFilePaths(PluginUpdateHandler.PluginsTranslationsFolder, Name + "*.language.xml", SearchOption.TopDirectoryOnly); foreach (string lang in lTranslationsInstalled) { string translation = File.Exists(lang) ? File.ReadAllText(lang) : string.Empty; Match m = r.Match(translation); if (m.Groups.Count != 2) { continue; } long lVerInstalled = 0; if (!long.TryParse(m.Groups[1].Value, out lVerInstalled)) { continue; } string sLang = UrlUtil.GetFileName(lang); TranslationVersionCheck tvc = Translations.Find(x => x.LangugageFile == sLang); if (tvc == null) { tvc = new TranslationVersionCheck() { LangugageFile = sLang }; Translations.Add(tvc); } tvc.Installed = lVerInstalled; } } catch (Exception) { } }
private void UpdateAvailableTranslations() { Dictionary <string, List <UpdateComponentInfo> > dUpdateInfo = new Dictionary <string, List <UpdateComponentInfo> >(); Dictionary <string, long> dResult = new Dictionary <string, long>(); Type t = typeof(KeePass.Program).Assembly.GetType("KeePass.Util.UpdateCheckEx"); if (t == null) { PluginDebug.AddError("Could not locate class 'UpdateCheckEx'", 0); return; } MethodInfo mi = t.GetMethod("DownloadInfoFiles", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Static); if (mi == null) { PluginDebug.AddError("Could not locate method 'DownloadInfoFiles'", 0); return; } if (string.IsNullOrEmpty(VersionURL)) { PluginDebug.AddError("Could not read plugin update url", 0); return; } dUpdateInfo = mi.Invoke(null, new object[] { new List <string>() { VersionURL }, null }) as Dictionary <string, List <UpdateComponentInfo> >; List <string> lTranslationsNew = new List <string>(); string[] cSplit = new string[] { "!", "!!!" }; foreach (KeyValuePair <string, List <UpdateComponentInfo> > kvp in dUpdateInfo) { if (kvp.Value == null) { continue; } Version vCheck = null; foreach (UpdateComponentInfo uci in kvp.Value) { //Github: <Plugin>!<language identifier> string[] sParts = uci.Name.Split(cSplit, StringSplitOptions.RemoveEmptyEntries); if (sParts.Length == 1) { vCheck = new Version(StrUtil.VersionToString(uci.VerAvailable, 2)); if (VersionAvailableIsUnknown()) { VersionAvailable = vCheck; } } if (!PluginUpdateHandler.VersionsEqual(VersionInstalled, vCheck)) { return; //Different version might require different translation files } if (sParts.Length != 2) { continue; } long lVer = 0; if (!long.TryParse(StrUtil.VersionToString(uci.VerAvailable), out lVer)) { continue; } string sLang = Name + "." + sParts[1].ToLowerInvariant() + ".language.xml"; TranslationVersionCheck tvc = Translations.Find(x => x.LangugageFile == sLang); if (tvc == null) { tvc = new TranslationVersionCheck() { LangugageFile = sLang }; Translations.Add(tvc); } tvc.Available = lVer; } } }