From b5d8f4e2484be70d5f780778f2c53988297bc20a Mon Sep 17 00:00:00 2001 From: RKrom Date: Mon, 26 Jul 2010 15:09:04 +0000 Subject: [PATCH] Removed GreenshotPlugin as we have everything in the GreenshotCore git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@712 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/LanguageHelper.cs | 451 ------------------ GreenshotPlugin/Core/PropertyHelper.cs | 118 ----- GreenshotPlugin/GreenshotPlugin.csproj | 73 --- .../Properties/AssemblyInfo.cs.template | 51 -- 4 files changed, 693 deletions(-) delete mode 100644 GreenshotPlugin/Core/LanguageHelper.cs delete mode 100644 GreenshotPlugin/Core/PropertyHelper.cs delete mode 100644 GreenshotPlugin/GreenshotPlugin.csproj delete mode 100644 GreenshotPlugin/Properties/AssemblyInfo.cs.template diff --git a/GreenshotPlugin/Core/LanguageHelper.cs b/GreenshotPlugin/Core/LanguageHelper.cs deleted file mode 100644 index ebc5bf700..000000000 --- a/GreenshotPlugin/Core/LanguageHelper.cs +++ /dev/null @@ -1,451 +0,0 @@ -/* - * 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 . - */ -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 GreenshotPlugin.Core { - - public interface ILanguage { - void Load(); - string GetString(Enum id); - string GetFormattedString(Enum id, object param); - string GetHelpFilePath(); - - /// - /// Set language - /// - /// wanted IETF - /// Actuall IETF - string SetLanguage(string cultureInfo); - void SynchronizeLanguageToCulture(); - string CurrentLanguage { - get; - } - - List SupportedLanguages { - get; - } - - String LanguageFilePattern { - get; - set; - } - - } - /// - /// Description of Language. - /// - 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 strings = new Dictionary(); - private List languages = new List(); - 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 SupportedLanguages { - get { - return languages; - } - } - - public void SynchronizeLanguageToCulture() { - if (!CurrentLanguage.Equals(Thread.CurrentThread.CurrentUICulture.Name)) { - SetLanguage(Thread.CurrentThread.CurrentUICulture.Name); - } - } - - /// - /// Set language - /// - /// wanted IETF - /// Actuall IETF - public string SetLanguage(string wantedIETF) { - LOG.Debug("SetLanguage called for : " + wantedIETF); - Dictionary identifiedLanguages = new Dictionary(); - - 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 LoadFiles(string languageFilePattern) { - List loadedLanguages = new List(); - List languageDirectories = new List(); - 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> keysPerLanguage = new Dictionary>(); - foreach(LanguageConfiguration languageToValidate in languages) { - List keys = new List(); - 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 fixedKeys = new List(); - foreach(Enum langKey in Enum.GetValues(languageKeys.GetType())) { - fixedKeys.Add(langKey.ToString()); - } - - foreach(string ietf in keysPerLanguage.Keys) { - List 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 keys = new List(); - 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 helpFiles = new List(); - // 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 Resources; - - public LanguageConfiguration() { - Resources = new List(); - } - - /// - /// loads a language configuration from a file path - /// - 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(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 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; - } - } -} diff --git a/GreenshotPlugin/Core/PropertyHelper.cs b/GreenshotPlugin/Core/PropertyHelper.cs deleted file mode 100644 index e61b8b89d..000000000 --- a/GreenshotPlugin/Core/PropertyHelper.cs +++ /dev/null @@ -1,118 +0,0 @@ -/* - * 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 . - */ -using System; -using System.Collections.Generic; -using System.IO; - -namespace GreenshotPlugin.Core { - /// - /// A Class to representate a simple "java" properties file - /// - public class Properties : Dictionary{ - private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Properties)); - - public string GetProperty(string key) { - try { - return this[key]; - } catch (KeyNotFoundException) { - return null; - } - } - /// - /// Split property with ',' and return the splitted string as a string[] - /// - 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; - } - } -} diff --git a/GreenshotPlugin/GreenshotPlugin.csproj b/GreenshotPlugin/GreenshotPlugin.csproj deleted file mode 100644 index 3eaeb9fa3..000000000 --- a/GreenshotPlugin/GreenshotPlugin.csproj +++ /dev/null @@ -1,73 +0,0 @@ - - - {5B924697-4DCD-4F98-85F1-105CB84B7341} - Debug - x86 - Library - GreenshotPlugin - GreenshotPlugin - v2.0 - Properties - OnBuildSuccess - C:\Users\Robin\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis - False - False - 4 - false - - - x86 - False - Auto - 4194304 - 4096 - - - bin\Debug\ - true - Full - False - True - DEBUG;TRACE - - - bin\Release\ - False - None - True - False - TRACE - - - - - ..\GreenshotCore\Lib\log4net.dll - - - - - - - - - - - - - - - - - - - - - {BDC408EE-DEA1-4474-B59D-7F05757B12EC} - GreenshotCore - - - - rmdir /S /Q "$(SolutionDir)bin\$(Configuration)\Plugins" -"$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs" - - \ No newline at end of file diff --git a/GreenshotPlugin/Properties/AssemblyInfo.cs.template b/GreenshotPlugin/Properties/AssemblyInfo.cs.template deleted file mode 100644 index 005c8c8b7..000000000 --- a/GreenshotPlugin/Properties/AssemblyInfo.cs.template +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 . - */ -#region Using directives - -using System; -using System.Reflection; -using System.Runtime.InteropServices; - -#endregion - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("GreenshotPlugin")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("GreenshotPlugin")] -[assembly: AssemblyCopyright("Copyright 2010")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// This sets the default COM visibility of types in the assembly to invisible. -// If you need to expose a type to COM, use [ComVisible(true)] on that type. -[assembly: ComVisible(false)] - -// The assembly version has following format : -// -// Major.Minor.Build.Revision -// -// You can specify all the values or you can use the default the Revision and -// Build Numbers by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.$WCREV$")]