public static void ImportPo(KPTranslation kpInto, string strFile) { if((strFile == null) || (strFile.Length == 0)) { Debug.Assert(false); return; } string strData = File.ReadAllText(strFile, StrUtil.Utf8); strData = StrUtil.NormalizeNewLines(strData, false); string[] vData = strData.Split('\n'); Dictionary<string, string> dict = new Dictionary<string, string>(); string strID = string.Empty; foreach(string strLine in vData) { string str = strLine.Trim(); if(str.StartsWith("msgid ", StrUtil.CaseIgnoreCmp)) strID = FilterPoValue(str.Substring(6)); else if(str.StartsWith("msgstr ", StrUtil.CaseIgnoreCmp)) { if(strID.Length > 0) { dict[strID] = FilterPoValue(str.Substring(7)); strID = string.Empty; } } } MergeDict(kpInto, dict); }
public static void Save(KPTranslation kpTrl, Stream sOut, IXmlSerializerEx xs) { if (xs == null) { throw new ArgumentNullException("xs"); } #if !KeePassLibSD GZipStream gz = new GZipStream(sOut, CompressionMode.Compress); #else GZipOutputStream gz = new GZipOutputStream(sOut); #endif XmlWriterSettings xws = new XmlWriterSettings(); xws.CheckCharacters = true; xws.Encoding = StrUtil.Utf8; xws.Indent = true; xws.IndentChars = "\t"; XmlWriter xw = XmlWriter.Create(gz, xws); xs.Serialize(xw, kpTrl); xw.Close(); gz.Close(); sOut.Close(); }
private static void MergeDict(KPTranslation kpInto, Dictionary<string, string> dict) { if(kpInto == null) { Debug.Assert(false); return; } if(dict == null) { Debug.Assert(false); return; } foreach(KPStringTable kpst in kpInto.StringTables) { foreach(KPStringTableItem kpsti in kpst.Strings) { string strTrl; if(dict.TryGetValue(kpsti.ValueEnglish, out strTrl)) kpsti.Value = strTrl; } } foreach(KPFormCustomization kpfc in kpInto.Forms) { string strTrlWnd; if(dict.TryGetValue(kpfc.Window.TextEnglish, out strTrlWnd)) kpfc.Window.Text = strTrlWnd; foreach(KPControlCustomization kpcc in kpfc.Controls) { string strTrlCtrl; if(dict.TryGetValue(kpcc.TextEnglish, out strTrlCtrl)) kpcc.Text = strTrlCtrl; } } }
public static void Save(KPTranslation kpTrl, Stream sOut, IXmlSerializerEx xs) { if (xs == null) { throw new ArgumentNullException("xs"); } #if !KeePassLibSD using (GZipStream gz = new GZipStream(sOut, CompressionMode.Compress)) #else using (GZipOutputStream gz = new GZipOutputStream(sOut)) #endif { using (XmlWriter xw = XmlUtilEx.CreateXmlWriter(gz)) { xs.Serialize(xw, kpTrl); } } #if KeePassUWP sOut.Dispose(); #else sOut.Close(); #endif }
public static void SaveToFile(KPTranslation kpTrl, string strFileName) { FileStream fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write, FileShare.None); #if !KeePassLibSD GZipStream gz = new GZipStream(fs, CompressionMode.Compress); #else GZipOutputStream gz = new GZipOutputStream(fs); #endif XmlWriterSettings xws = new XmlWriterSettings(); xws.CheckCharacters = true; xws.Encoding = new UTF8Encoding(false); xws.Indent = true; xws.IndentChars = "\t"; XmlWriter xw = XmlWriter.Create(gz, xws); XmlSerializer xmlSerial = new XmlSerializer(typeof(KPTranslation)); xmlSerial.Serialize(xw, kpTrl); xw.Close(); gz.Close(); fs.Close(); }
public static KPTranslation Load(Stream s, IXmlSerializerEx xs) { if (xs == null) { throw new ArgumentNullException("xs"); } KPTranslation kpTrl = null; #if !KeePassLibSD using (GZipStream gz = new GZipStream(s, CompressionMode.Decompress)) #else using (GZipInputStream gz = new GZipInputStream(s)) #endif { kpTrl = (xs.Deserialize(gz) as KPTranslation); } #if KeePassUWP s.Dispose(); #else s.Close(); #endif return(kpTrl); }
public static void SaveToFile(KPTranslation kpTrl, string strFileName, IXmlSerializerEx xs) { if (xs == null) { throw new ArgumentNullException("xs"); } FileStream fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write, FileShare.None); #if !KeePassLibSD GZipStream gz = new GZipStream(fs, CompressionMode.Compress); #else GZipOutputStream gz = new GZipOutputStream(fs); #endif XmlWriterSettings xws = new XmlWriterSettings(); xws.CheckCharacters = true; xws.Encoding = StrUtil.Utf8; xws.Indent = true; xws.IndentChars = "\t"; XmlWriter xw = XmlWriter.Create(gz, xws); xs.Serialize(xw, kpTrl); xw.Close(); gz.Close(); fs.Close(); }
public static void Save(KPTranslation kpTrl, string strFileName, IXmlSerializerEx xs) { using (FileStream fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write, FileShare.None)) { Save(kpTrl, fs, xs); } }
public static KPTranslation Load(string strFile, IXmlSerializerEx xs) { KPTranslation kpTrl = null; using (FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { kpTrl = Load(fs, xs); } return(kpTrl); }
public static string Validate(KPTranslation trl) { if(trl == null) { Debug.Assert(false); return null; } foreach(KPFormCustomization kpfc in trl.Forms) { string str = Validate(kpfc); if(str != null) return str; } return null; }
public static void Import1xLng(KPTranslation kpInto, string strFile) { if((strFile == null) || (strFile.Length == 0)) { Debug.Assert(false); return; } string strData = File.ReadAllText(strFile, StrUtil.Utf8); Dictionary<string, string> dict = new Dictionary<string, string>(); const int nStatePreEn = 0; const int nStateInEn = 1; const int nStateBetween = 2; const int nStateInTrl = 3; StringBuilder sbEn = new StringBuilder(); StringBuilder sbTrl = new StringBuilder(); int nState = nStatePreEn; for(int i = 0; i < strData.Length; ++i) { char ch = strData[i]; if(ch == '|') { if(nState == nStatePreEn) nState = nStateInEn; else if(nState == nStateInEn) nState = nStateBetween; else if(nState == nStateBetween) nState = nStateInTrl; else if(nState == nStateInTrl) { dict[sbEn.ToString()] = sbTrl.ToString(); sbEn = new StringBuilder(); sbTrl = new StringBuilder(); nState = nStatePreEn; } } else if(nState == nStateInEn) sbEn.Append(ch); else if(nState == nStateInTrl) sbTrl.Append(ch); } Debug.Assert(nState == nStatePreEn); dict[string.Empty] = string.Empty; MergeDict(kpInto, dict); }
public static KPTranslation LoadFromFile(string strFile) { FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read); #if !KeePassLibSD GZipStream gz = new GZipStream(fs, CompressionMode.Decompress); #else GZipInputStream gz = new GZipInputStream(fs); #endif XmlSerializer xmlSerial = new XmlSerializer(typeof(KPTranslation)); KPTranslation kpTrl = (xmlSerial.Deserialize(gz) as KPTranslation); gz.Close(); fs.Close(); return(kpTrl); }
public static KPTranslation LoadFromFile(string strFile, IXmlSerializerEx xs) { if (xs == null) { throw new ArgumentNullException("xs"); } FileStream fs = new FileStream(strFile, FileMode.Open, FileAccess.Read, FileShare.Read); #if !KeePassLibSD GZipStream gz = new GZipStream(fs, CompressionMode.Decompress); #else GZipInputStream gz = new GZipInputStream(fs); #endif KPTranslation kpTrl = (xs.Deserialize(gz) as KPTranslation); gz.Close(); fs.Close(); return(kpTrl); }
public static void SaveToFile(KPTranslation kpTrl, string strFileName, IXmlSerializerEx xs) { if(xs == null) throw new ArgumentNullException("xs"); FileStream fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write, FileShare.None); #if !KeePassLibSD GZipStream gz = new GZipStream(fs, CompressionMode.Compress); #else GZipOutputStream gz = new GZipOutputStream(fs); #endif XmlWriterSettings xws = new XmlWriterSettings(); xws.CheckCharacters = true; xws.Encoding = StrUtil.Utf8; xws.Indent = true; xws.IndentChars = "\t"; XmlWriter xw = XmlWriter.Create(gz, xws); xs.Serialize(xw, kpTrl); xw.Close(); gz.Close(); fs.Close(); }
private static void LoadTranslation() { string strLangFile = m_appConfig.Application.LanguageFile; if(!string.IsNullOrEmpty(strLangFile)) { string[] vLangDirs = new string[]{ AppConfigSerializer.AppDataDirectory, AppConfigSerializer.LocalAppDataDirectory, UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), false, false) }; foreach(string strLangDir in vLangDirs) { string strLangPath = UrlUtil.EnsureTerminatingSeparator( strLangDir, false) + strLangFile; try { XmlSerializerEx xs = new XmlSerializerEx(typeof(KPTranslation)); m_kpTranslation = KPTranslation.LoadFromFile(strLangPath, xs); KPRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePass.Resources.KPRes")); KLRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePassLib.Resources.KLRes")); StrUtil.RightToLeft = m_kpTranslation.Properties.RightToLeft; break; } catch(DirectoryNotFoundException) { } // Ignore catch(FileNotFoundException) { } // Ignore catch(Exception) { Debug.Assert(false); } } } }
private static void ImportPo(KPTranslation trlInto, IOConnectionInfo ioc) { TrlImport.ImportPo(trlInto, ioc.Path); }
public static void Save(KPTranslation kpTrl, string strFileName, IXmlSerializerEx xs) { using(FileStream fs = new FileStream(strFileName, FileMode.Create, FileAccess.Write, FileShare.None)) { Save(kpTrl, fs, xs); } }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); int nRandomSeed = (int)DateTime.Now.Ticks; // Prevent overflow (see Random class constructor) if(nRandomSeed == int.MinValue) nRandomSeed = 17; m_rndGlobal = new Random(nRandomSeed); // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; Kdb4File.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if(m_appConfig.Logging.Enabled) AppLogEx.Open(PwDefs.ShortProductName); AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; string strLangFile = m_appConfig.Application.LanguageFile; if((strLangFile != null) && (strLangFile.Length > 0)) { strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true) + strLangFile; try { m_kpTranslation = KPTranslation.LoadFromFile(strLangFile); KPRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePass.Resources.KPRes")); KLRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePassLib.Resources.KLRes")); } catch(FileNotFoundException) { } // Ignore catch(Exception) { Debug.Assert(false); } } m_cmdLineArgs = new CommandLineArgs(args); if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } else if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch(Exception) { Debug.Assert(false); } if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { try { NativeMethods.SendMessage((IntPtr)NativeMethods.HWND_BROADCAST, m_nAppMessage, (IntPtr)AppMessage.Exit, IntPtr.Zero); } catch(Exception) { Debug.Assert(false); } MainCleanUp(); return; } Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); #if DEBUG m_formMain = new MainForm(); Application.Run(m_formMain); #else try { m_formMain = new MainForm(); Application.Run(m_formMain); } catch(Exception exPrg) { MessageService.ShowFatal(exPrg); } #endif Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } if(mSingleLock != null) { GC.KeepAlive(mSingleLock); } }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); // Required InitEnvSecurity(); int nRandomSeed = (int)DateTime.Now.Ticks; // Prevent overflow (see Random class constructor) if(nRandomSeed == int.MinValue) nRandomSeed = 17; m_rndGlobal = new Random(nRandomSeed); // Set global localized strings PwDatabase.LocalizedAppName = PwDefs.ShortProductName; Kdb4File.DetermineLanguageId(); m_appConfig = AppConfigSerializer.Load(); if(m_appConfig.Logging.Enabled) AppLogEx.Open(PwDefs.ShortProductName); AppPolicy.Current = m_appConfig.Security.Policy.CloneDeep(); m_ecasTriggers = m_appConfig.Application.TriggerSystem; m_ecasTriggers.SetToInitialState(); string strHelpFile = UrlUtil.StripExtension(WinUtil.GetExecutable()) + ".chm"; AppHelp.LocalHelpFile = strHelpFile; string strLangFile = m_appConfig.Application.LanguageFile; if((strLangFile != null) && (strLangFile.Length > 0)) { strLangFile = UrlUtil.GetFileDirectory(WinUtil.GetExecutable(), true, false) + strLangFile; try { m_kpTranslation = KPTranslation.LoadFromFile(strLangFile); KPRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePass.Resources.KPRes")); KLRes.SetTranslatedStrings( m_kpTranslation.SafeGetStringTableDictionary( "KeePassLib.Resources.KLRes")); StrUtil.RightToLeft = m_kpTranslation.Properties.RightToLeft; } catch(FileNotFoundException) { } // Ignore catch(Exception) { Debug.Assert(false); } } if(m_appConfig.Application.Start.PluginCacheClearOnce) { PlgxCache.Clear(); m_appConfig.Application.Start.PluginCacheClearOnce = false; AppConfigSerializer.Save(Program.Config); } m_cmdLineArgs = new CommandLineArgs(args); if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtRegister] != null) { ShellUtil.RegisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId, KPRes.FileExtName, WinUtil.GetExecutable(), PwDefs.ShortProductName, false); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.FileExtUnregister] != null) { ShellUtil.UnregisterExtension(AppDefs.FileExtension.FileExt, AppDefs.FileExtension.ExtId); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoad] != null) { // All important .NET assemblies are in memory now already try { SelfTest.Perform(); } catch(Exception) { Debug.Assert(false); } MainCleanUp(); return; } /* else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadRegister] != null) { string strPreLoadPath = WinUtil.GetExecutable().Trim(); if(strPreLoadPath.StartsWith("\"") == false) strPreLoadPath = "\"" + strPreLoadPath + "\""; ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, strPreLoadPath, @"--" + AppDefs.CommandLineOptions.PreLoad, true); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PreLoadUnregister] != null) { ShellUtil.RegisterPreLoad(AppDefs.PreLoadName, string.Empty, string.Empty, false); MainCleanUp(); return; } */ else if((m_cmdLineArgs[AppDefs.CommandLineOptions.Help] != null) || (m_cmdLineArgs[AppDefs.CommandLineOptions.HelpLong] != null)) { AppHelp.ShowHelp(AppDefs.HelpTopics.CommandLine, null); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetUrlOverride] != null) { Program.Config.Integration.UrlOverride = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetUrlOverride]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigClearUrlOverride] != null) { Program.Config.Integration.UrlOverride = string.Empty; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigGetUrlOverride] != null) { try { string strFileOut = UrlUtil.EnsureTerminatingSeparator( Path.GetTempPath(), false) + "KeePass_UrlOverride.tmp"; string strContent = ("[KeePass]\r\nKeeURLOverride=" + Program.Config.Integration.UrlOverride + "\r\n"); File.WriteAllText(strFileOut, strContent); } catch(Exception) { Debug.Assert(false); } MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.ConfigSetLanguageFile] != null) { Program.Config.Application.LanguageFile = m_cmdLineArgs[ AppDefs.CommandLineOptions.ConfigSetLanguageFile]; AppConfigSerializer.Save(Program.Config); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreate] != null) { PlgxPlugin.CreateFromCommandLine(); MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.PlgxCreateInfo] != null) { PlgxPlugin.CreateInfoFile(m_cmdLineArgs.FileName); MainCleanUp(); return; } #if (DEBUG && !KeePassLibSD) else if(m_cmdLineArgs[AppDefs.CommandLineOptions.MakePopularPasswordTable] != null) { PopularPasswords.MakeList(); MainCleanUp(); return; } #endif try { m_nAppMessage = NativeMethods.RegisterWindowMessage(m_strWndMsgID); } catch(Exception) { Debug.Assert(false); } if(m_cmdLineArgs[AppDefs.CommandLineOptions.ExitAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Exit); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.AutoType] != null) { BroadcastAppMessageAndCleanUp(AppMessage.AutoType); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.OpenEntryUrl] != null) { string strEntryUuid = m_cmdLineArgs[AppDefs.CommandLineOptions.Uuid]; if(!string.IsNullOrEmpty(strEntryUuid)) { IpcParamEx ipUrl = new IpcParamEx(IpcUtilEx.CmdOpenEntryUrl, strEntryUuid, null, null, null, null); IpcUtilEx.SendGlobalMessage(ipUrl); } MainCleanUp(); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.LockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Lock); return; } else if(m_cmdLineArgs[AppDefs.CommandLineOptions.UnlockAll] != null) { BroadcastAppMessageAndCleanUp(AppMessage.Unlock); return; } Mutex mSingleLock = TrySingleInstanceLock(AppDefs.MutexName, true); if((mSingleLock == null) && m_appConfig.Integration.LimitToSingleInstance) { ActivatePreviousInstance(args); MainCleanUp(); return; } Mutex mGlobalNotify = TryGlobalInstanceNotify(AppDefs.MutexNameGlobal); AutoType.InitStatic(); UserActivityNotifyFilter nfActivity = new UserActivityNotifyFilter(); Application.AddMessageFilter(nfActivity); #if DEBUG m_formMain = new MainForm(); Application.Run(m_formMain); #else try { m_formMain = new MainForm(); Application.Run(m_formMain); } catch(Exception exPrg) { MessageService.ShowFatal(exPrg); } #endif Application.RemoveMessageFilter(nfActivity); Debug.Assert(GlobalWindowManager.WindowCount == 0); Debug.Assert(MessageService.CurrentMessageCount == 0); MainCleanUp(); if(mGlobalNotify != null) { GC.KeepAlive(mGlobalNotify); } if(mSingleLock != null) { GC.KeepAlive(mSingleLock); } }
public static void Save(KPTranslation kpTrl, Stream sOut, IXmlSerializerEx xs) { if(xs == null) throw new ArgumentNullException("xs"); #if !KeePassLibSD GZipStream gz = new GZipStream(sOut, CompressionMode.Compress); #else GZipOutputStream gz = new GZipOutputStream(sOut); #endif XmlWriterSettings xws = new XmlWriterSettings(); xws.CheckCharacters = true; xws.Encoding = StrUtil.Utf8; xws.Indent = true; xws.IndentChars = "\t"; XmlWriter xw = XmlWriter.Create(gz, xws); xs.Serialize(xw, kpTrl); xw.Close(); gz.Close(); sOut.Close(); }