mirror of
https://github.com/greenshot/greenshot
synced 2025-07-31 04:00:13 -07:00
Embedded the default en-US language file, so the greenshot.exe should always run without language files.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1608 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
83570e855b
commit
41365fab86
3 changed files with 68 additions and 34 deletions
|
@ -275,9 +275,9 @@
|
||||||
<None Include="Languages\language-el-GR.xml">
|
<None Include="Languages\language-el-GR.xml">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Include="Languages\language-en-US.xml">
|
<EmbeddedResource Include="Languages\language-en-US.xml">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</EmbeddedResource>
|
||||||
<None Include="Languages\language-es-ES.xml">
|
<None Include="Languages\language-es-ES.xml">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|
|
@ -279,6 +279,21 @@ namespace GreenshotPlugin.Core {
|
||||||
LOG.Error("Error trying for read directory " + path, e);
|
LOG.Error("Error trying for read directory " + path, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (loadedLanguages.Count == 0) {
|
||||||
|
// Try to force internal english
|
||||||
|
try {
|
||||||
|
LOG.Info("No languages found, using embedded en-US.");
|
||||||
|
using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Greenshot.Languages.language-en-US.xml")) {
|
||||||
|
LanguageConfiguration languageConfig = LanguageConfiguration.Load(stream);
|
||||||
|
if (languageConfig != null) {
|
||||||
|
loadedLanguages.Add(languageConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ie) {
|
||||||
|
LOG.Error("Can't read internal 'Greenshot.Languages.language-en-US.xml'", ie);
|
||||||
|
}
|
||||||
|
}
|
||||||
return loadedLanguages;
|
return loadedLanguages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,39 +514,60 @@ namespace GreenshotPlugin.Core {
|
||||||
/// loads a language configuration from a file path
|
/// loads a language configuration from a file path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static LanguageConfiguration Load(string path) {
|
public static LanguageConfiguration Load(string path) {
|
||||||
LanguageConfiguration ret = null;
|
LanguageConfiguration languageConfiguration = null;
|
||||||
try {
|
try {
|
||||||
XmlDocument doc = new XmlDocument();
|
XmlDocument xmlDocument = new XmlDocument();
|
||||||
doc.Load(path);
|
xmlDocument.Load(path);
|
||||||
XmlNodeList nodes = doc.GetElementsByTagName("language");
|
languageConfiguration = ProcessXML(xmlDocument);
|
||||||
if(nodes.Count > 0) {
|
languageConfiguration.File = path;
|
||||||
ret = new LanguageConfiguration();
|
} catch(Exception e) {
|
||||||
ret.File = path;
|
LOG.Error("Could not load language file "+path, e);
|
||||||
XmlNode node = nodes.Item(0);
|
}
|
||||||
ret.Description = node.Attributes["description"].Value;
|
return languageConfiguration;
|
||||||
ret.Ietf = node.Attributes["ietf"].Value;
|
|
||||||
ret.Version = node.Attributes["version"].Value;
|
|
||||||
if (node.Attributes["languagegroup"] != null) {
|
|
||||||
string languageGroup = node.Attributes["languagegroup"].Value;
|
|
||||||
ret.LanguageGroup = languageGroup.ToLower();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlNodeList resourceNodes = doc.GetElementsByTagName("resource");
|
/// <summary>
|
||||||
ret.Resources = new List<Resource>(resourceNodes.Count);
|
/// loads a language configuration from a stream
|
||||||
|
/// </summary>
|
||||||
|
public static LanguageConfiguration Load(Stream stream) {
|
||||||
|
LanguageConfiguration languageConfiguration = null;
|
||||||
|
try {
|
||||||
|
XmlDocument xmlDocument = new XmlDocument();
|
||||||
|
xmlDocument.Load(stream);
|
||||||
|
languageConfiguration = ProcessXML(xmlDocument);
|
||||||
|
languageConfiguration.File = "internal";
|
||||||
|
} catch(Exception e) {
|
||||||
|
LOG.Error("Could not load internal language file", e);
|
||||||
|
}
|
||||||
|
return languageConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static LanguageConfiguration ProcessXML(XmlDocument xmlDocument) {
|
||||||
|
LanguageConfiguration languageConfiguration = null;
|
||||||
|
XmlNodeList nodes = xmlDocument.GetElementsByTagName("language");
|
||||||
|
if(nodes.Count > 0) {
|
||||||
|
languageConfiguration = new LanguageConfiguration();
|
||||||
|
XmlNode node = nodes.Item(0);
|
||||||
|
languageConfiguration.Description = node.Attributes["description"].Value;
|
||||||
|
languageConfiguration.Ietf = node.Attributes["ietf"].Value;
|
||||||
|
languageConfiguration.Version = node.Attributes["version"].Value;
|
||||||
|
if (node.Attributes["languagegroup"] != null) {
|
||||||
|
string languageGroup = node.Attributes["languagegroup"].Value;
|
||||||
|
languageConfiguration.LanguageGroup = languageGroup.ToLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
XmlNodeList resourceNodes = xmlDocument.GetElementsByTagName("resource");
|
||||||
|
languageConfiguration.Resources = new List<Resource>(resourceNodes.Count);
|
||||||
foreach(XmlNode resourceNode in resourceNodes) {
|
foreach(XmlNode resourceNode in resourceNodes) {
|
||||||
Resource res = new Resource();
|
Resource res = new Resource();
|
||||||
res.Name = resourceNode.Attributes["name"].Value;
|
res.Name = resourceNode.Attributes["name"].Value;
|
||||||
res.Text = resourceNode.InnerText;
|
res.Text = resourceNode.InnerText;
|
||||||
ret.Resources.Add(res);
|
languageConfiguration.Resources.Add(res);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new XmlException("Root element <language> is missing");
|
throw new XmlException("Root element <language> is missing");
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
return languageConfiguration;
|
||||||
LOG.Error("Could not load language file "+path, e);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,7 @@ namespace IniFile {
|
||||||
}
|
}
|
||||||
string forcedIni = Path.Combine(applicationStartupPath, applicationName + INI_EXTENSION);
|
string forcedIni = Path.Combine(applicationStartupPath, applicationName + INI_EXTENSION);
|
||||||
if (!File.Exists(forcedIni)) {
|
if (!File.Exists(forcedIni)) {
|
||||||
using (File.Create(forcedIni)) {
|
using (File.Create(forcedIni)) {}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue