Updates for refactoring, everything should compile again

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@713 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2010-07-26 15:11:09 +00:00
parent b5d8f4e248
commit 1c2462874d
43 changed files with 649 additions and 68 deletions

View file

@ -41,7 +41,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
<HintPath>..\GreenshotCore\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="MODI11">
<HintPath>lib\MODI11.dll</HintPath>
@ -76,12 +76,12 @@
<None Include="Properties\AssemblyInfo.cs.template" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
</ProjectReference>
<Folder Include="Languages" />
<Folder Include="lib" />
<ProjectReference Include="..\GreenshotCore\GreenshotCore.csproj">
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
<Name>GreenshotCore</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>

View file

@ -24,7 +24,7 @@ using System.Globalization;
using System.Resources;
using System.Threading;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace GreenshotOCR {
/// <summary>

View file

@ -28,8 +28,9 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Core;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Microsoft.Win32;
namespace GreenshotOCR {

View file

@ -23,7 +23,7 @@ using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace GreenshotOCR {
/// <summary>

View file

@ -41,7 +41,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
<HintPath>..\GreenshotCore\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
@ -65,9 +65,9 @@
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"</PostBuildEvent>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
<ProjectReference Include="..\GreenshotCore\GreenshotCore.csproj">
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
<Name>GreenshotCore</Name>
</ProjectReference>
</ItemGroup>
</Project>

View file

@ -28,6 +28,7 @@ using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using Greenshot.Capturing;
using Greenshot.Plugin;
namespace RunAtOutput {

View file

@ -25,8 +25,9 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Core;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
namespace FixTitle {
/// <summary>

View file

@ -41,7 +41,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
<HintPath>..\GreenshotCore\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Windows.Forms" />
@ -58,9 +58,9 @@ copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(SolutionDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
<ProjectReference Include="..\GreenshotCore\GreenshotCore.csproj">
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
<Name>GreenshotCore</Name>
</ProjectReference>
</ItemGroup>
</Project>

View file

@ -31,9 +31,9 @@ using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using System.Windows.Forms;
using Greenshot.Core;
using Greenshot.Drawing;
using Greenshot.Drawing.Fields;
using GreenshotPlugin.Core;
namespace Greenshot.Configuration {
public enum ScreenshotDestinations {Editor=1, FileDefault=2, FileWithDialog=4, Clipboard=8, Printer=16, EMail=32}

View file

@ -27,7 +27,7 @@ using System.Threading;
using System.Windows.Forms;
using System.Xml;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot.Configuration {
/// <summary>

View file

@ -24,7 +24,7 @@ using System.Reflection;
using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot {
/// <summary>

View file

@ -25,8 +25,8 @@ using System.Web;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Core;
using Greenshot.Helpers;
using GreenshotPlugin.Core;
namespace Greenshot.Forms {
public partial class BugReportForm : Form {

View file

@ -31,11 +31,11 @@ using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Configuration;
using Greenshot.Core;
using Greenshot.Drawing;
using Greenshot.Helpers;
using Greenshot.Plugin;
using Greenshot.UnmanagedHelpers;
using GreenshotPlugin.Core;
namespace Greenshot.Forms {
/// <summary>

View file

@ -26,7 +26,7 @@ using System.Threading;
using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot {
/// <summary>

View file

@ -41,7 +41,7 @@ using Greenshot.Drawing.Fields.Binding;
using Greenshot.Help;
using Greenshot.Helpers;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot.Forms {
/// <summary>

View file

@ -23,7 +23,7 @@ using System.Drawing;
using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot {
/// <summary>

View file

@ -39,7 +39,7 @@ using Greenshot.Help;
using Greenshot.Helpers;
using Greenshot.Plugin;
using Greenshot.UnmanagedHelpers;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot {
/// <summary>

View file

@ -23,7 +23,7 @@ using System.Drawing;
using System.Windows.Forms;
using Greenshot.Configuration;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot.Forms {
/// <summary>

View file

@ -29,7 +29,7 @@ using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Helpers;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot {
/// <summary>

View file

@ -21,7 +21,7 @@
using System;
using System.IO;
using Greenshot.Configuration;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Greenshot.Help {
/// <summary>

View file

@ -29,9 +29,9 @@ using System.Threading;
using System.Windows.Forms;
using Greenshot.Configuration;
using Greenshot.Core;
using Greenshot.Drawing;
using Greenshot.UnmanagedHelpers;
using GreenshotPlugin.Core;
namespace Greenshot.Helpers {
/// <summary>

View file

@ -26,9 +26,9 @@ using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Configuration;
using Greenshot.Core;
using Greenshot.Forms;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
namespace Greenshot.Helpers {
/// <summary>

View file

@ -29,8 +29,8 @@ using System.Text;
using System.Threading;
using System.Windows.Forms;
using Greenshot.Core;
using Greenshot.UnmanagedHelpers;
using GreenshotPlugin.Core;
/// <summary>
/// Code for handling with "windows"

View file

@ -3,8 +3,8 @@ Source: ..\..\bin\Release\*; DestDir: {app}; Flags: overwritereadonly ignorevers
Source: ..\..\bin\Release\Languages\*; DestDir: {app}\Languages; Flags: overwritereadonly ignoreversion replacesameversion
Source: ..\additional_files\*; DestDir: {app}; Flags: overwritereadonly recursesubdirs ignoreversion replacesameversion
;Flickr Plugin
;Source: ..\..\bin\Release\Plugins\GreenshotFlickrPlugin\*; DestDir: {app}\Plugins\GreenshotFlickrPlugin; Components: plugins\flickr; Flags: overwritereadonly recursesubdirs ignoreversion replacesameversion;
;Source: ..\..\bin\Release\Languages\Plugins\GreenshotFlickrPlugin\*; DestDir: {app}\Languages\Plugins\GreenshotFlickrPlugin; Components: plugins\flickr; Flags: overwritereadonly ignoreversion replacesameversion;
Source: ..\..\bin\Release\Plugins\GreenshotFlickrPlugin\*; DestDir: {app}\Plugins\GreenshotFlickrPlugin; Components: plugins\flickr; Flags: overwritereadonly recursesubdirs ignoreversion replacesameversion;
Source: ..\..\bin\Release\Languages\Plugins\GreenshotFlickrPlugin\*; DestDir: {app}\Languages\Plugins\GreenshotFlickrPlugin; Components: plugins\flickr; Flags: overwritereadonly ignoreversion replacesameversion;
;OCR Plugin
;Source: ..\..\bin\Release\Plugins\Greenshot-OCR-Plugin\*; DestDir: {app}\Plugins\Greenshot-OCR-Plugin; Components: plugins\ocr; Flags: overwritereadonly recursesubdirs ignoreversion replacesameversion;
;Source: ..\..\bin\Release\Languages\Plugins\Greenshot-OCR-Plugin\*; DestDir: {app}\Languages\Plugins\Greenshot-OCR-Plugin; Components: plugins\ocr; Flags: overwritereadonly ignoreversion replacesameversion;
@ -38,12 +38,12 @@ Name: de; MessagesFile: compiler:Languages\German.isl
Name: nl; MessagesFile: compiler:Languages\Dutch.isl
[Tasks]
Name: startup; Description: "{cm:startup}";
;[Components]
;Name: "plugins"; Description: "Plugins"; Types: Full
[Components]
Name: "plugins"; Description: "Plugins"; Types: Full
;Name: "plugins\ocr"; Description: "OCR Plugin"; Types: Full
;Name: "plugins\jira"; Description: "JIRA Plugin"; Types: Full
;Name: "plugins\titlefix"; Description: "Title-fix Plugin"; Types: Full
;Name: "plugins\flickr"; Description: "Flickr Plugin"; Types: Full
Name: "plugins\flickr"; Description: "Flickr Plugin"; Types: Full
[CustomMessages]
en.dotnetmissing=This setup requires the .NET Framework v2.0.%nDo you want to download the framework now?
de.dotnetmissing=Dieses Programm benötigt Microsoft .NET Framework v2.0.%nWollen Sie das Framework jetzt downloaden?

View file

@ -26,7 +26,7 @@ using System.Text;
using System.Windows.Forms;
using GreenshotConfluencePlugin;
using GreenshotPlugin.Core;
using Greenshot.Core;
/// <summary>
/// For details see the Confluence API site

View file

@ -27,8 +27,10 @@ using System.Text;
using System.Windows.Forms;
using Confluence;
using Greenshot.Capturing;
using Greenshot.Core;
using Greenshot.Forms;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
namespace GreenshotConfluencePlugin {
/// <summary>

View file

@ -22,7 +22,7 @@ using System;
using System.Drawing;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace GreenshotConfluencePlugin {
/// <summary>

View file

@ -41,7 +41,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
<HintPath>..\GreenshotCore\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
@ -87,10 +87,6 @@
<ItemGroup>
<Folder Include="Forms" />
<Folder Include="Languages" />
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
</ProjectReference>
<WebReferences Include="Web References\" />
<WebReferenceUrl Include="http://confluence/rpc/soap-axis/confluenceservice-v1%3fwsdl">
<UrlBehavior>Static</UrlBehavior>
@ -98,6 +94,10 @@
<RelPath>Web References\confluence</RelPath>
<Namespace>Confluence</Namespace>
</WebReferenceUrl>
<ProjectReference Include="..\GreenshotCore\GreenshotCore.csproj">
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
<Name>GreenshotCore</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>

View file

@ -24,7 +24,7 @@ using System.Globalization;
using System.Resources;
using System.Threading;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace GreenshotConfluencePlugin {
/// <summary>

View file

@ -0,0 +1,451 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* 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 1 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, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
namespace Greenshot.Core {
public interface ILanguage {
void Load();
string GetString(Enum id);
string GetFormattedString(Enum id, object param);
string GetHelpFilePath();
/// <summary>
/// Set language
/// </summary>
/// <param name="wantedIETF">wanted IETF</param>
/// <returns>Actuall IETF </returns>
string SetLanguage(string cultureInfo);
void SynchronizeLanguageToCulture();
string CurrentLanguage {
get;
}
List<LanguageConfiguration> SupportedLanguages {
get;
}
String LanguageFilePattern {
get;
set;
}
}
/// <summary>
/// Description of Language.
/// </summary>
public class LanguageContainer : ILanguage {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(LanguageContainer));
private static char [] TRIMCHARS = new char[] {' ', '\t', '\n', '\r'};
private const string DEFAULT_LANGUAGE= "en-US";
private static string APPLICATIONDATA_LANGUAGE_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),@"Greenshot\Languages\");
private static string STARTUP_LANGUAGE_PATH = Path.Combine(Application.StartupPath, @"Languages\");
private const string HELP_FILENAME_PATTERN = @"help-*.html";
private Dictionary<string, string> strings = new Dictionary<string, string>();
private List<LanguageConfiguration> languages = new List<LanguageConfiguration>();
private string currentIETF = null;
private string languageFilePattern;
public LanguageContainer() {
}
public String LanguageFilePattern {
get {
return languageFilePattern;
}
set {
languageFilePattern = value;
}
}
public void Load() {
languages = LoadFiles(languageFilePattern);
}
public string CurrentLanguage {
get {
return currentIETF;
}
}
public List<LanguageConfiguration> SupportedLanguages {
get {
return languages;
}
}
public void SynchronizeLanguageToCulture() {
if (!CurrentLanguage.Equals(Thread.CurrentThread.CurrentUICulture.Name)) {
SetLanguage(Thread.CurrentThread.CurrentUICulture.Name);
}
}
/// <summary>
/// Set language
/// </summary>
/// <param name="wantedIETF">wanted IETF</param>
/// <returns>Actuall IETF </returns>
public string SetLanguage(string wantedIETF) {
LOG.Debug("SetLanguage called for : " + wantedIETF);
Dictionary<string, LanguageConfiguration> identifiedLanguages = new Dictionary<string, LanguageConfiguration>();
if (languages == null || languages.Count == 0) {
throw new FileNotFoundException("No language files found!");
}
// Find selected languages in available languages
foreach(LanguageConfiguration language in languages) {
LOG.Debug("Found language: " + language.Ietf);
identifiedLanguages.Add(language.Ietf, language);
}
LanguageConfiguration selectedLanguage = null;
try {
selectedLanguage = identifiedLanguages[wantedIETF];
} catch (KeyNotFoundException) {
LOG.Warn("Selecteded language " + wantedIETF + " not found.");
}
// Make best match for language (e.g. en -> "en-US")
if (selectedLanguage == null) {
foreach(string ietf in identifiedLanguages.Keys) {
if (ietf.StartsWith(wantedIETF)) {
try {
selectedLanguage = identifiedLanguages[ietf];
LOG.Info("Selecteded language " + ietf + " by near match for: " + wantedIETF);
wantedIETF = ietf;
break;
} catch (KeyNotFoundException) {
LOG.Warn("Selecteded language " + wantedIETF + " not found.");
}
}
}
}
if (selectedLanguage == null && !DEFAULT_LANGUAGE.Equals(wantedIETF)) {
try {
selectedLanguage = identifiedLanguages[DEFAULT_LANGUAGE];
} catch (KeyNotFoundException) {
LOG.Warn("No english language file found!!");
}
}
if (selectedLanguage == null) {
// Select first (maybe only) language!
selectedLanguage = languages[0];
LOG.Warn("Selected " + selectedLanguage.Ietf + " as fallback language!");
}
// build directionary for the strings
strings.Clear();
foreach(Resource resource in selectedLanguage.Resources) {
AddResource(resource);
}
currentIETF = selectedLanguage.Ietf;
return currentIETF;
}
private void AddResource(Resource resource) {
try {
if (resource.Text != null) {
strings.Add(resource.Name, resource.Text.Trim(TRIMCHARS));
} else {
LOG.Warn("Resource is null: " + resource.Name);
strings.Add(resource.Name, "");
}
} catch (ArgumentException ae) {
LOG.Error("Problem adding " + resource.Name, ae);
throw ae;
}
}
private List<LanguageConfiguration> LoadFiles(string languageFilePattern) {
List<LanguageConfiguration> loadedLanguages = new List<LanguageConfiguration>();
List<string> languageDirectories = new List<string>();
languageDirectories.Add(STARTUP_LANGUAGE_PATH);
languageDirectories.Add(APPLICATIONDATA_LANGUAGE_PATH);
foreach(string path in languageDirectories) {
// Search in executable directory
if (Directory.Exists(path)) {
foreach(string languageFile in Directory.GetFiles(path, languageFilePattern, SearchOption.AllDirectories)) {
LanguageConfiguration languageConfig = LanguageConfiguration.Load(languageFile);
if (languageConfig != null) {
LOG.Info("Loaded language: " + languageConfig.Description);
loadedLanguages.Add(languageConfig);
}
}
}
}
return loadedLanguages;
}
public void Validate(Enum languageKeys) {
Dictionary<string, List<string>> keysPerLanguage = new Dictionary<string, List<string>>();
foreach(LanguageConfiguration languageToValidate in languages) {
List<string> keys = new List<string>();
foreach(Resource resource in languageToValidate.Resources) {
keys.Add(resource.Name);
}
keys.Sort();
keysPerLanguage.Add(languageToValidate.Ietf, keys);
}
// Make list of values in the enum
List<string> fixedKeys = new List<string>();
foreach(Enum langKey in Enum.GetValues(languageKeys.GetType())) {
fixedKeys.Add(langKey.ToString());
}
foreach(string ietf in keysPerLanguage.Keys) {
List<string> keys = keysPerLanguage[ietf];
foreach(string key in fixedKeys) {
if (!keys.Contains(key)) {
LOG.Warn(ietf + " is missing resource with name [" + key + "]");
}
}
foreach(string key in keys) {
if (!fixedKeys.Contains(key)) {
LOG.Warn(ietf + " has additional resource with name [" + key + "]");
}
}
}
}
private void ToEnum() {
if (!LOG.IsDebugEnabled) {
return;
}
StringBuilder EnumClass = new StringBuilder();
EnumClass.AppendLine("/*");
EnumClass.AppendLine(" * Auto generated");
EnumClass.AppendLine(" */");
EnumClass.AppendLine("using System;");
EnumClass.AppendLine();
EnumClass.AppendLine("namespace Greenshot.Configuration {");
EnumClass.AppendLine(" public enum LangKey {");
List<string> keys = new List<string>();
foreach(LanguageConfiguration foundLanguage in languages) {
if (foundLanguage.Ietf.Equals(DEFAULT_LANGUAGE)) {
foreach(Resource resource in foundLanguage.Resources) {
keys.Add(resource.Name);
}
}
}
keys.Sort();
bool added = false;
foreach(string key in keys) {
if (added) {
EnumClass.AppendLine(",");
}
EnumClass.Append(" " + key);
added = true;
}
EnumClass.AppendLine();
EnumClass.AppendLine(" }");
EnumClass.AppendLine("}");
LOG.Debug("LangKeys should be: \r\n" + EnumClass.ToString());
}
public string GetString(Enum id) {
if(!strings.ContainsKey(id.ToString())) {
AdoptMissingResourcesFromDefaultLanguage();
}
try {
return strings[id.ToString()];
} catch (KeyNotFoundException) {
return "string ###"+id+"### not found";
}
}
public string GetFormattedString(Enum id, object param) {
if(!strings.ContainsKey(id.ToString())) {
AdoptMissingResourcesFromDefaultLanguage();
}
try {
return String.Format(strings[id.ToString()], param);
} catch (KeyNotFoundException) {
return "string ###"+id+"### not found";
}
}
private void AdoptMissingResourcesFromDefaultLanguage() {
LanguageConfiguration defaultLanguageConfiguration = GetDefaultLanguageConfiguration();
if (defaultLanguageConfiguration != null) {
foreach(Resource resource in GetDefaultLanguageConfiguration().Resources) {
if(!strings.ContainsKey(resource.Name)) {
AddResource(resource);
if(LOG.IsWarnEnabled) {
LOG.Warn("Adopted missing string resource from default language: "+resource.Name);
}
}
}
} else {
LOG.Warn("Default language file is missing! The default language file is: " + DEFAULT_LANGUAGE);
}
}
private LanguageConfiguration GetDefaultLanguageConfiguration() {
foreach(LanguageConfiguration language in languages) {
if(language.Ietf == DEFAULT_LANGUAGE) return language;
}
return null;
}
/// finds a returns the path of the best matching help file.
/// 1st tries to find file for currentLanguage, 2nd for defaultLanguage.
/// if neither is found, the first help file found is returned
public string GetHelpFilePath() {
List<string> helpFiles = new List<string>();
// Search in executable directory
if (Directory.Exists(STARTUP_LANGUAGE_PATH)) {
helpFiles.AddRange(Directory.GetFiles(STARTUP_LANGUAGE_PATH, HELP_FILENAME_PATTERN, SearchOption.AllDirectories));
}
// Search in ApplicationData directory
if (Directory.Exists(APPLICATIONDATA_LANGUAGE_PATH)) {
helpFiles.AddRange(Directory.GetFiles(APPLICATIONDATA_LANGUAGE_PATH, HELP_FILENAME_PATTERN, SearchOption.AllDirectories));
}
foreach(string helpFile in helpFiles) {
if(helpFile.EndsWith(currentIETF+".html")) {
return helpFile;
}
}
foreach(string helpFile in helpFiles) {
if(helpFile.EndsWith(DEFAULT_LANGUAGE+".html")) {
return helpFile;
}
}
LOG.Warn("Help file not found for default language, will load "+helpFiles[0]);
return helpFiles[0];
}
}
public class LanguageConfiguration {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(LanguageConfiguration));
public string description;
public string Description {get;set;}
public string ietf;
public string Ietf {get;set;}
public string version;
public string Version {get;set;}
public string file;
public string File {get;set;}
public List<Resource> Resources;
public LanguageConfiguration() {
Resources = new List<Resource>();
}
/// <summary>
/// loads a language configuration from a file path
/// </summary>
public static LanguageConfiguration Load(string path) {
LanguageConfiguration ret = null;
try {
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNodeList nodes = doc.GetElementsByTagName("language");
if(nodes.Count > 0) {
ret = new LanguageConfiguration();
ret.File = path;
XmlNode node = nodes.Item(0);
ret.Description = node.Attributes["description"].Value;
ret.Ietf = node.Attributes["ietf"].Value;
ret.Version = node.Attributes["version"].Value;
XmlNodeList resourceNodes = doc.GetElementsByTagName("resource");
ret.Resources = new List<Resource>(resourceNodes.Count);
foreach(XmlNode resourceNode in resourceNodes) {
Resource res = new Resource();
res.Name = resourceNode.Attributes["name"].Value;
res.Text = resourceNode.InnerText;
ret.Resources.Add(res);
}
} else {
throw new XmlException("Root element <language> is missing");
}
} catch(Exception e) {
LOG.Error("Could not load language file "+path, e);
}
return ret;
}
}
public class Resource {
public string name;
public string Name {get; set;}
public string text;
public string Text {get; set;}
public override int GetHashCode() {
int hash = 7;
if (Text != null) {
hash = hash ^ Text.GetHashCode();
}
if (Name != null) {
hash = hash ^ Name.GetHashCode();
}
return hash;
}
public override bool Equals(object obj) {
if (obj == null) {
return false;
}
if (obj is Resource) {
Resource other = (Resource) obj;
if(Name == null) {
if (other.Name != null) {
return false;
}
return true;
}
if(Text == null) {
if (other.Text != null) {
return false;
}
return true;
}
return (Name.Equals(other.Name) && Text.Equals(other.Text));
}
return false;
}
}
}

View file

@ -0,0 +1,118 @@
/*
* Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2010 Thomas Braun, Jens Klingen, Robin Krom
*
* For more information see: http://getgreenshot.org/
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
*
* 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 1 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, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
namespace Greenshot.Core {
/// <summary>
/// A Class to representate a simple "java" properties file
/// </summary>
public class Properties : Dictionary<string, string >{
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Properties));
public string GetProperty(string key) {
try {
return this[key];
} catch (KeyNotFoundException) {
return null;
}
}
/// <summary>
/// Split property with ',' and return the splitted string as a string[]
/// </summary>
public string[] GetPropertyAsArray(string key) {
try {
string array = this[key];
return array.Split(new Char[] {','});
} catch (KeyNotFoundException) {
return null;
}
}
public bool GetBoolProperty(string key) {
return bool.Parse(this[key]);
}
public int GetIntProperty(string key) {
return int.Parse(this[key]);
}
public void AddProperty(string key, string value) {
Add(key, value);
}
public void AddBoolProperty(string key, bool value) {
AddProperty(key, value.ToString());
}
public void ChangeProperty(string key, string value) {
if (this.ContainsKey(key)) {
this[key] = value;
} else {
throw new KeyNotFoundException(key);
}
}
public void ChangeBoolProperty(string key, bool value) {
ChangeProperty(key, value.ToString());
}
public void write(string filename) {
using ( TextWriter textWriter = new StreamWriter(filename)) {
foreach(string key in Keys) {
textWriter.WriteLine(key +"=" + this[key]);
}
}
}
public void write(string filename, string header) {
using ( TextWriter textWriter = new StreamWriter(filename)) {
if (header != null) {
textWriter.WriteLine(header);
}
foreach(string key in Keys) {
textWriter.WriteLine(key +"=" + this[key]);
}
}
}
// Read properties file
public static Properties read(string filename) {
LOG.Debug("Reading properties from file: " + filename);
if (!File.Exists(filename)) {
return null;
}
Properties properties = new Properties();
foreach (string line in File.ReadAllLines(filename)) {
if (line == null) {
continue;
}
string currentLine = line.Trim();
if (!currentLine.StartsWith("#") && currentLine.IndexOf('=') > 0) {
string [] split = currentLine.Split(new Char[] {'='}, 2);
if (split != null && split.Length == 2) {
string name = split[0];
if (name == null || name.Length < 1) {
continue;
}
properties.Add(name.Trim(), split[1]);
}
}
}
return properties;
}
}
}

View file

@ -39,12 +39,16 @@
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Folder Include="Core" />
<Folder Include="Interfaces\Drawing" />
<Folder Include="Interfaces\Drawing\Fields" />
<Folder Include="Interfaces\Forms" />
@ -53,6 +57,8 @@
<Folder Include="Lib" />
<Folder Include="Interfaces" />
<Folder Include="UnmanagedHelpers" />
<Compile Include="Core\LanguageHelper.cs" />
<Compile Include="Core\PropertyHelper.cs" />
<Compile Include="Interfaces\Capturing\Capture.cs" />
<Compile Include="Interfaces\Drawing\IDrawableContainer.cs" />
<Compile Include="Interfaces\Drawing\Fields\IField.cs" />

View file

@ -30,9 +30,9 @@ using System.Windows.Forms;
using FlickrNet;
using Greenshot.Capturing;
using Greenshot.Core;
using Greenshot.Forms;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Microsoft.Win32;
namespace GreenshotFlickrPlugin {

View file

@ -83,10 +83,6 @@
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
<Name>GreenshotCore</Name>
</ProjectReference>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>

View file

@ -24,7 +24,7 @@ using System.Globalization;
using System.Resources;
using System.Threading;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace GreenshotFlickrPlugin {
/// <summary>

View file

@ -28,7 +28,7 @@ using System.Net;
using System.Text;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.Core;
using Jira;
namespace GreenshotJiraPlugin {

View file

@ -22,7 +22,7 @@ using System;
using System.Drawing;
using System.Windows.Forms;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace GreenshotJiraPlugin {
/// <summary>

View file

@ -41,7 +41,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
<HintPath>..\GreenshotCore\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
@ -94,9 +94,9 @@
<RelPath>Web References\JiraSoap</RelPath>
<Namespace>Jira</Namespace>
</WebReferenceUrl>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
<ProjectReference Include="..\GreenshotCore\GreenshotCore.csproj">
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
<Name>GreenshotCore</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>

View file

@ -26,7 +26,7 @@ using System.Text;
using System.Windows.Forms;
using GreenshotJiraPlugin;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace Jira {
#region transport classes

View file

@ -26,8 +26,10 @@ using System.IO;
using System.Text;
using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Core;
using Greenshot.Forms;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Jira;
namespace GreenshotJiraPlugin {

View file

@ -24,7 +24,7 @@ using System.Globalization;
using System.Resources;
using System.Threading;
using GreenshotPlugin.Core;
using Greenshot.Core;
namespace GreenshotJiraPlugin {
/// <summary>

View file

@ -26,6 +26,9 @@ using System.IO;
using System.Text;
using System.Windows.Forms;
using Greenshot.Capturing;
using Greenshot.Drawing;
using Greenshot.Forms;
using Greenshot.Plugin;
namespace PluginExample {

View file

@ -41,7 +41,7 @@
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\Greenshot\Lib\log4net.dll</HintPath>
<HintPath>..\GreenshotCore\Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
@ -60,15 +60,15 @@
<DependentUpon>SettingsForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotPlugin\GreenshotPlugin.csproj">
<Project>{5B924697-4DCD-4F98-85F1-105CB84B7341}</Project>
<Name>GreenshotPlugin</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)"
copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp"</PostBuildEvent>
<PreBuildEvent>"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs"</PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\GreenshotCore\GreenshotCore.csproj">
<Project>{BDC408EE-DEA1-4474-B59D-7F05757B12EC}</Project>
<Name>GreenshotCore</Name>
</ProjectReference>
</ItemGroup>
</Project>