mirror of
https://github.com/greenshot/greenshot
synced 2025-08-13 18:27:03 -07:00
BUG-2037: Added a small fix to improve the ini stability, also added some other small changes which were pending.
This commit is contained in:
parent
4ff0f090bb
commit
3b214133e4
5 changed files with 57 additions and 46 deletions
|
@ -34,12 +34,12 @@
|
|||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
|
||||
<ItemGroup>
|
||||
<Reference Include="Dapplo.HttpExtensions, Version=0.5.36.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.HttpExtensions.0.5.36\lib\net45\Dapplo.HttpExtensions.dll</HintPath>
|
||||
<Reference Include="Dapplo.HttpExtensions, Version=0.5.43.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.HttpExtensions.0.5.43\lib\net45\Dapplo.HttpExtensions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Dapplo.Jira, Version=0.1.61.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.Jira.0.1.61\lib\net45\Dapplo.Jira.dll</HintPath>
|
||||
<Reference Include="Dapplo.Jira, Version=0.1.65.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapplo.Jira.0.1.65\lib\net45\Dapplo.Jira.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Dapplo.Log.Facade, Version=0.5.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Dapplo.HttpExtensions" version="0.5.36" targetFramework="net45" />
|
||||
<package id="Dapplo.Jira" version="0.1.61" targetFramework="net45" />
|
||||
<package id="Dapplo.HttpExtensions" version="0.5.43" targetFramework="net45" />
|
||||
<package id="Dapplo.Jira" version="0.1.65" targetFramework="net45" />
|
||||
<package id="Dapplo.Log.Facade" version="0.5.4" targetFramework="net45" />
|
||||
<package id="LibZ.Tool" version="1.2.0.0" targetFramework="net45" />
|
||||
<package id="Svg" version="2.2.1" targetFramework="net45" />
|
||||
|
|
|
@ -51,17 +51,17 @@ namespace Greenshot.IniFile {
|
|||
/// <summary>
|
||||
/// A Dictionary with all the sections stored by section name
|
||||
/// </summary>
|
||||
private static readonly Dictionary<string, IniSection> SectionMap = new Dictionary<string, IniSection>();
|
||||
private static readonly IDictionary<string, IniSection> SectionMap = new Dictionary<string, IniSection>();
|
||||
|
||||
/// <summary>
|
||||
/// A Dictionary with the properties for a section stored by section name
|
||||
/// </summary>
|
||||
private static Dictionary<string, Dictionary<string, string>> _sections = new Dictionary<string, Dictionary<string, string>>();
|
||||
private static IDictionary<string, IDictionary<string, string>> _sections = new Dictionary<string, IDictionary<string, string>>();
|
||||
|
||||
/// <summary>
|
||||
/// A Dictionary with the fixed-properties for a section stored by section name
|
||||
/// </summary>
|
||||
private static Dictionary<string, Dictionary<string, string>> _fixedProperties;
|
||||
private static IDictionary<string, IDictionary<string, string>> _fixedProperties;
|
||||
|
||||
/// <summary>
|
||||
/// Stores if we checked for portable
|
||||
|
@ -231,7 +231,7 @@ namespace Greenshot.IniFile {
|
|||
/// </summary>
|
||||
public static void Reload() {
|
||||
// Clear the current properties
|
||||
_sections = new Dictionary<string, Dictionary<string, string>>();
|
||||
_sections = new Dictionary<string, IDictionary<string, string>>();
|
||||
// Load the defaults
|
||||
Read(CreateIniLocation(_configName + DefaultsPostfix + IniExtension, true));
|
||||
// Load the normal
|
||||
|
@ -264,7 +264,7 @@ namespace Greenshot.IniFile {
|
|||
{
|
||||
return;
|
||||
}
|
||||
Dictionary<string, string> fixedPropertiesForSection;
|
||||
IDictionary<string, string> fixedPropertiesForSection;
|
||||
if (!_fixedProperties.TryGetValue(section.IniSectionAttribute.Name, out fixedPropertiesForSection))
|
||||
{
|
||||
return;
|
||||
|
@ -280,23 +280,23 @@ namespace Greenshot.IniFile {
|
|||
/// Read the ini file into the Dictionary
|
||||
/// </summary>
|
||||
/// <param name="iniLocation">Path & Filename of ini file</param>
|
||||
private static Dictionary<string, Dictionary<string, string>> Read(string iniLocation) {
|
||||
private static IDictionary<string, IDictionary<string, string>> Read(string iniLocation) {
|
||||
if (!File.Exists(iniLocation)) {
|
||||
Log.Info("Can't find file: " + iniLocation);
|
||||
return null;
|
||||
}
|
||||
Log.InfoFormat("Loading ini-file: {0}", iniLocation);
|
||||
//LOG.Info("Reading ini-properties from file: " + iniLocation);
|
||||
Dictionary<string, Dictionary<string, string>> newSections = IniReader.read(iniLocation, Encoding.UTF8);
|
||||
var newSections = IniReader.Read(iniLocation, Encoding.UTF8);
|
||||
// Merge the newly loaded properties to the already available
|
||||
foreach(string section in newSections.Keys) {
|
||||
Dictionary<string, string> newProperties = newSections[section];
|
||||
IDictionary<string, string> newProperties = newSections[section];
|
||||
if (!_sections.ContainsKey(section)) {
|
||||
// This section is not yet loaded, simply add the complete section
|
||||
_sections.Add(section, newProperties);
|
||||
} else {
|
||||
// Overwrite or add every property from the newly loaded section to the available one
|
||||
Dictionary<string, string> currentProperties = _sections[section];
|
||||
var currentProperties = _sections[section];
|
||||
foreach(string propertyName in newProperties.Keys) {
|
||||
string propertyValue = newProperties[propertyName];
|
||||
if (currentProperties.ContainsKey(propertyName)) {
|
||||
|
@ -446,7 +446,7 @@ namespace Greenshot.IniFile {
|
|||
writer.WriteLine("; The reason could be that the section {0} just hasn't been used, a plugin has an error and can't claim it or maybe the whole section {0} is obsolete.", sectionName);
|
||||
// Write section name
|
||||
writer.WriteLine("[{0}]", sectionName);
|
||||
Dictionary<string, string> properties = _sections[sectionName];
|
||||
var properties = _sections[sectionName];
|
||||
// Loop and write properties
|
||||
foreach (string propertyName in properties.Keys) {
|
||||
writer.WriteLine("{0}={1}", propertyName, properties[propertyName]);
|
||||
|
|
|
@ -24,40 +24,51 @@ using System.IO;
|
|||
using System.Text;
|
||||
|
||||
namespace Greenshot.IniFile {
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class IniReader {
|
||||
private const string SECTION_START = "[";
|
||||
private const string SECTION_END = "]";
|
||||
private const string COMMENT = ";";
|
||||
private static readonly char[] ASSIGNMENT = new[] { '=' };
|
||||
private const string SectionStart = "[";
|
||||
private const string SectionEnd = "]";
|
||||
private const string Comment = ";";
|
||||
private static readonly char[] Assignment = { '=' };
|
||||
|
||||
/**
|
||||
* Read an ini file to a Dictionary, each key is a section and the value is a Dictionary with name and values.
|
||||
*/
|
||||
public static Dictionary<string, Dictionary<string, string>> read(string path, Encoding encoding) {
|
||||
Dictionary<string, Dictionary<string, string>> ini = new Dictionary<string, Dictionary<string, string>>();
|
||||
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 1024)) {
|
||||
using (StreamReader reader = new StreamReader(fileStream, encoding)) {
|
||||
Dictionary<string, string> nameValues = new Dictionary<string, string>();
|
||||
while (!reader.EndOfStream) {
|
||||
string line = reader.ReadLine();
|
||||
if (line != null) {
|
||||
string cleanLine = line.Trim();
|
||||
if (cleanLine.Length == 0 || cleanLine.StartsWith(COMMENT)) {
|
||||
continue;
|
||||
}
|
||||
if (cleanLine.StartsWith(SECTION_START)) {
|
||||
string section = line.Replace(SECTION_START, "").Replace(SECTION_END, "").Trim();
|
||||
/// <summary>
|
||||
/// Read an ini file to a Dictionary, each key is a section and the value is a Dictionary with name and values.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
public static IDictionary<string, IDictionary<string, string>> Read(string path, Encoding encoding) {
|
||||
var ini = new Dictionary<string, IDictionary<string, string>>();
|
||||
using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 1024)) {
|
||||
using (var streamReader = new StreamReader(fileStream, encoding)) {
|
||||
IDictionary<string, string> nameValues = new Dictionary<string, string>();
|
||||
while (!streamReader.EndOfStream) {
|
||||
string line = streamReader.ReadLine();
|
||||
if (line == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string cleanLine = line.Trim();
|
||||
if (cleanLine.Length == 0 || cleanLine.StartsWith(Comment)) {
|
||||
continue;
|
||||
}
|
||||
if (cleanLine.StartsWith(SectionStart)) {
|
||||
string section = line.Replace(SectionStart, string.Empty).Replace(SectionEnd, string.Empty).Trim();
|
||||
if (!ini.TryGetValue(section, out nameValues))
|
||||
{
|
||||
nameValues = new Dictionary<string, string>();
|
||||
ini.Add(section, nameValues);
|
||||
}
|
||||
} else {
|
||||
string[] keyvalueSplitter = line.Split(Assignment, 2);
|
||||
string name = keyvalueSplitter[0];
|
||||
string inivalue = keyvalueSplitter.Length > 1 ? keyvalueSplitter[1] : null;
|
||||
if (nameValues.ContainsKey(name)) {
|
||||
nameValues[name] = inivalue;
|
||||
} else {
|
||||
string[] keyvalueSplitter = line.Split(ASSIGNMENT, 2);
|
||||
string name = keyvalueSplitter[0];
|
||||
string inivalue = keyvalueSplitter.Length > 1 ? keyvalueSplitter[1] : null;
|
||||
if (nameValues.ContainsKey(name)) {
|
||||
nameValues[name] = inivalue;
|
||||
} else {
|
||||
nameValues.Add(name, inivalue);
|
||||
}
|
||||
nameValues.Add(name, inivalue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -369,7 +369,7 @@ namespace GreenshotPlugin.UnmanagedHelpers {
|
|||
bV5GreenMask = (uint)255 << 8;
|
||||
bV5BlueMask = 255;
|
||||
bV5AlphaMask = (uint)255 << 24;
|
||||
bV5CSType = 1934772034; // sRGB
|
||||
bV5CSType = 0x73524742; // LCS_sRGB
|
||||
bV5Endpoints = new CIEXYZTRIPLE
|
||||
{
|
||||
ciexyzBlue = new CIEXYZ(0),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue