1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using KeePass.App;
using KeePass.App.Configuration;
using KeePass.UI;
using KeePass.Resources;
using KeePass.Util;
using KeePass.Util.XmlSerialization;
using KeePassLib;
using KeePassLib.Translation;
using KeePassLib.Utility;
namespace KeePass.Forms
{
public partial class LanguageForm : Form, IGwmWindow
{
public bool CanCloseWithoutDataLoss { get { return true; } }
public LanguageForm()
{
InitializeComponent();
Program.Translation.ApplyTo(this);
}
private void OnFormLoad(object sender, EventArgs e)
{
GlobalWindowManager.AddWindow(this, this);
BannerFactory.CreateBannerEx(this, m_bannerImage,
Properties.Resources.B48x48_Keyboard_Layout,
KPRes.SelectLanguage, KPRes.SelectLanguageDesc);
this.Icon = new Icon("/usr/share/keepass2/KeePass.ico");
this.Text = KPRes.SelectLanguage;
int nWidth = m_lvLanguages.ClientRectangle.Width / 4;
m_lvLanguages.Columns.Add(KPRes.AvailableLanguages, nWidth);
m_lvLanguages.Columns.Add(KPRes.Version, nWidth);
m_lvLanguages.Columns.Add(KPRes.Author, nWidth);
m_lvLanguages.Columns.Add(KPRes.Contact, nWidth);
ListViewItem lvi = m_lvLanguages.Items.Add("English", 0);
lvi.SubItems.Add(PwDefs.VersionString);
lvi.SubItems.Add(AppDefs.DefaultTrlAuthor);
lvi.SubItems.Add(AppDefs.DefaultTrlContact);
List<string> vList = new List<string>();
GetAvailableTranslations(AppConfigSerializer.AppDataDirectory, vList);
GetAvailableTranslations(AppConfigSerializer.LocalAppDataDirectory, vList);
string strExe = WinUtil.GetExecutable();
string strPath = UrlUtil.GetFileDirectory(strExe, false, true);
GetAvailableTranslations(strPath, vList);
}
private void GetAvailableTranslations(string strPath, List<string> vList)
{
try
{
DirectoryInfo di = new DirectoryInfo(strPath);
FileInfo[] vFiles = di.GetFiles();
foreach(FileInfo fi in vFiles)
{
string strFullName = fi.FullName;
if(strFullName.EndsWith("." + KPTranslation.FileExtension,
StrUtil.CaseIgnoreCmp))
{
string strFileName = UrlUtil.GetFileName(strFullName);
bool bFound = false;
foreach(string strExisting in vList)
{
if(strExisting.Equals(strFileName, StrUtil.CaseIgnoreCmp))
{
bFound = true;
break;
}
}
if(bFound) continue;
try
{
XmlSerializerEx xs = new XmlSerializerEx(typeof(KPTranslation));
KPTranslation kpTrl = KPTranslation.LoadFromFile(
strFullName, xs);
ListViewItem lvi = m_lvLanguages.Items.Add(
kpTrl.Properties.NameEnglish, 0);
lvi.SubItems.Add(kpTrl.Properties.ApplicationVersion);
lvi.SubItems.Add(kpTrl.Properties.AuthorName);
lvi.SubItems.Add(kpTrl.Properties.AuthorContact);
lvi.Tag = strFileName;
vList.Add(strFileName);
}
catch(Exception ex)
{
MessageService.ShowWarning(ex.Message);
}
}
}
}
catch(Exception) { } // Directory might not exist or cause access violation
}
private void OnBtnClose(object sender, EventArgs e)
{
}
private void OnLanguagesItemActivate(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection lvic = m_lvLanguages.SelectedItems;
if((lvic == null) || (lvic.Count != 1)) return;
if(lvic[0].Index == 0) // First item selected = English
{
if(Program.Config.Application.LanguageFile.Length == 0)
return; // Is English already
Program.Config.Application.LanguageFile = string.Empty;
}
else
{
string strSelID = (lvic[0].Tag as string);
if(strSelID == Program.Config.Application.LanguageFile) return;
Program.Config.Application.LanguageFile = strSelID;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
private void OnFormClosed(object sender, FormClosedEventArgs e)
{
GlobalWindowManager.RemoveWindow(this);
}
private void OnBtnGetMore(object sender, EventArgs e)
{
WinUtil.OpenUrl(PwDefs.TranslationsUrl, null);
}
}
}
|