mirror of
https://github.com/greenshot/greenshot
synced 2025-07-06 04:52:16 -07:00
Modified the configuration handling, added code to remove tokens when upgrading from 1.2 as these no longer work. See #421
This commit is contained in:
parent
36a285ebd4
commit
48675b01f0
5 changed files with 121 additions and 79 deletions
|
@ -388,89 +388,64 @@ namespace Greenshot.Base.Core
|
||||||
return ExperimentalFeatures != null && ExperimentalFeatures.Contains(experimentalFeature);
|
return ExperimentalFeatures != null && ExperimentalFeatures.Contains(experimentalFeature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string CreateOutputFilePath()
|
||||||
|
{
|
||||||
|
if (IniConfig.IsPortable)
|
||||||
|
{
|
||||||
|
string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots");
|
||||||
|
if (!Directory.Exists(pafOutputFilePath))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(pafOutputFilePath);
|
||||||
|
return pafOutputFilePath;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// Problem creating directory, fallback to Desktop
|
||||||
|
LOG.Warn(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return pafOutputFilePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Supply values we can't put as defaults
|
/// Supply values we can't put as defaults
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="property">The property to return a default for</param>
|
/// <param name="property">The property to return a default for</param>
|
||||||
/// <returns>object with the default value for the supplied property</returns>
|
/// <returns>object with the default value for the supplied property</returns>
|
||||||
public override object GetDefault(string property)
|
public override object GetDefault(string property) =>
|
||||||
{
|
property switch
|
||||||
switch (property)
|
|
||||||
{
|
{
|
||||||
case nameof(ExcludePlugins):
|
nameof(ExcludePlugins) => new List<string>(),
|
||||||
case nameof(IncludePlugins):
|
nameof(IncludePlugins) => new List<string>(),
|
||||||
return new List<string>();
|
nameof(OutputFileAsFullpath) => IniConfig.IsPortable ? Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots\dummy.png") : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "dummy.png"),
|
||||||
case nameof(OutputFileAsFullpath):
|
nameof(OutputFilePath) => CreateOutputFilePath(),
|
||||||
if (IniConfig.IsPortable)
|
nameof(DWMBackgroundColor) => Color.Transparent,
|
||||||
{
|
nameof(ActiveTitleFixes) => new List<string> {
|
||||||
return Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots\dummy.png");
|
"Firefox",
|
||||||
}
|
"IE",
|
||||||
|
"Chrome"
|
||||||
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "dummy.png");
|
},
|
||||||
case nameof(OutputFilePath):
|
nameof(TitleFixMatcher) => new Dictionary<string, string> {
|
||||||
if (IniConfig.IsPortable)
|
{ "Firefox", " - Mozilla Firefox.*" },
|
||||||
{
|
{ "IE", " - (Microsoft|Windows) Internet Explorer.*" },
|
||||||
string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots");
|
{ "Chrome", " - Google Chrome.*" }
|
||||||
if (!Directory.Exists(pafOutputFilePath))
|
},
|
||||||
{
|
nameof(TitleFixReplacer) => new Dictionary<string, string> {
|
||||||
try
|
{ "Firefox", string.Empty },
|
||||||
{
|
{ "IE", string.Empty },
|
||||||
Directory.CreateDirectory(pafOutputFilePath);
|
{ "Chrome", string.Empty }
|
||||||
return pafOutputFilePath;
|
},
|
||||||
}
|
_ => null
|
||||||
catch (Exception ex)
|
};
|
||||||
{
|
|
||||||
LOG.Warn(ex);
|
|
||||||
// Problem creating directory, fallback to Desktop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return pafOutputFilePath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
|
||||||
case nameof(DWMBackgroundColor):
|
|
||||||
return Color.Transparent;
|
|
||||||
case nameof(ActiveTitleFixes):
|
|
||||||
return new List<string>
|
|
||||||
{
|
|
||||||
"Firefox",
|
|
||||||
"IE",
|
|
||||||
"Chrome"
|
|
||||||
};
|
|
||||||
case nameof(TitleFixMatcher):
|
|
||||||
return new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"Firefox", " - Mozilla Firefox.*"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IE", " - (Microsoft|Windows) Internet Explorer.*"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Chrome", " - Google Chrome.*"
|
|
||||||
}
|
|
||||||
};
|
|
||||||
case nameof(TitleFixReplacer):
|
|
||||||
return new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"Firefox", string.Empty
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"IE", string.Empty
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Chrome", string.Empty
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method will be called before converting the property, making to possible to correct a certain value
|
/// This method will be called before converting the property, making to possible to correct a certain value
|
||||||
/// Can be used when migration is needed
|
/// Can be used when migration is needed
|
||||||
|
@ -540,8 +515,9 @@ namespace Greenshot.Base.Core
|
||||||
OutputFileAutoReduceColors = false;
|
OutputFileAutoReduceColors = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isUpgradeFrom12 = LastSaveWithVersion?.StartsWith("1.2") ?? false;
|
||||||
// Fix for excessive feed checking
|
// Fix for excessive feed checking
|
||||||
if (UpdateCheckInterval != 0 && UpdateCheckInterval <= 7 && LastSaveWithVersion.StartsWith("1.2"))
|
if (UpdateCheckInterval != 0 && UpdateCheckInterval <= 7 && isUpgradeFrom12)
|
||||||
{
|
{
|
||||||
UpdateCheckInterval = 14;
|
UpdateCheckInterval = 14;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.Enums;
|
using Greenshot.Base.Core.Enums;
|
||||||
using Greenshot.Base.IniFile;
|
using Greenshot.Base.IniFile;
|
||||||
using Greenshot.Plugin.Box.Forms;
|
using Greenshot.Plugin.Box.Forms;
|
||||||
|
@ -75,5 +76,20 @@ namespace Greenshot.Plugin.Box
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Upgrade certain values
|
||||||
|
/// </summary>
|
||||||
|
public override void AfterLoad()
|
||||||
|
{
|
||||||
|
var coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
bool isUpgradeFrom12 = coreConfiguration.LastSaveWithVersion?.StartsWith("1.2") ?? false;
|
||||||
|
// Clear token when we upgrade from 1.2 to 1.3 as it is no longer valid, discussed in #421
|
||||||
|
if (!isUpgradeFrom12) return;
|
||||||
|
|
||||||
|
// We have an upgrade, remove all previous credentials.
|
||||||
|
RefreshToken = null;
|
||||||
|
AccessToken = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.Enums;
|
using Greenshot.Base.Core.Enums;
|
||||||
using Greenshot.Base.IniFile;
|
using Greenshot.Base.IniFile;
|
||||||
using Greenshot.Plugin.Dropbox.Forms;
|
using Greenshot.Plugin.Dropbox.Forms;
|
||||||
|
@ -69,5 +70,20 @@ namespace Greenshot.Plugin.Dropbox
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Upgrade certain values
|
||||||
|
/// </summary>
|
||||||
|
public override void AfterLoad()
|
||||||
|
{
|
||||||
|
var coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
bool isUpgradeFrom12 = coreConfiguration.LastSaveWithVersion?.StartsWith("1.2") ?? false;
|
||||||
|
// Clear token when we upgrade from 1.2 to 1.3 as it is no longer valid, discussed in #421
|
||||||
|
if (!isUpgradeFrom12) return;
|
||||||
|
|
||||||
|
// We have an upgrade, remove all previous credentials.
|
||||||
|
RefreshToken = null;
|
||||||
|
AccessToken = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.Enums;
|
using Greenshot.Base.Core.Enums;
|
||||||
using Greenshot.Base.IniFile;
|
using Greenshot.Base.IniFile;
|
||||||
using Greenshot.Plugin.Flickr.Forms;
|
using Greenshot.Plugin.Flickr.Forms;
|
||||||
|
@ -86,5 +87,21 @@ namespace Greenshot.Plugin.Flickr
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Upgrade certain values
|
||||||
|
/// </summary>
|
||||||
|
public override void AfterLoad()
|
||||||
|
{
|
||||||
|
var coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
bool isUpgradeFrom12 = coreConfiguration.LastSaveWithVersion?.StartsWith("1.2") ?? false;
|
||||||
|
// Clear token when we upgrade from 1.2 to 1.3 as it is no longer valid, discussed in #421
|
||||||
|
if (!isUpgradeFrom12) return;
|
||||||
|
|
||||||
|
// We have an upgrade, remove all previous credentials.
|
||||||
|
FlickrToken = null;
|
||||||
|
FlickrTokenSecret = null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -22,6 +22,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Greenshot.Base.Core;
|
||||||
using Greenshot.Base.Core.Enums;
|
using Greenshot.Base.Core.Enums;
|
||||||
using Greenshot.Base.IniFile;
|
using Greenshot.Base.IniFile;
|
||||||
using Greenshot.Plugin.Imgur.Forms;
|
using Greenshot.Plugin.Imgur.Forms;
|
||||||
|
@ -84,6 +85,22 @@ namespace Greenshot.Plugin.Imgur
|
||||||
public Dictionary<string, ImgurInfo> runtimeImgurHistory = new Dictionary<string, ImgurInfo>();
|
public Dictionary<string, ImgurInfo> runtimeImgurHistory = new Dictionary<string, ImgurInfo>();
|
||||||
public int Credits { get; set; }
|
public int Credits { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Upgrade certain values
|
||||||
|
/// </summary>
|
||||||
|
public override void AfterLoad()
|
||||||
|
{
|
||||||
|
var coreConfiguration = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
|
bool isUpgradeFrom12 = coreConfiguration.LastSaveWithVersion?.StartsWith("1.2") ?? false;
|
||||||
|
// Clear token when we upgrade from 1.2 to 1.3 as it is no longer valid, discussed in #421
|
||||||
|
if (!isUpgradeFrom12) return;
|
||||||
|
|
||||||
|
// We have an upgrade, remove all previous credentials.
|
||||||
|
AccessToken = null;
|
||||||
|
RefreshToken = null;
|
||||||
|
AccessTokenExpires = default;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Supply values we can't put as defaults
|
/// Supply values we can't put as defaults
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -92,7 +109,7 @@ namespace Greenshot.Plugin.Imgur
|
||||||
public override object GetDefault(string property) =>
|
public override object GetDefault(string property) =>
|
||||||
property switch
|
property switch
|
||||||
{
|
{
|
||||||
"ImgurUploadHistory" => new Dictionary<string, string>(),
|
nameof(ImgurUploadHistory) => new Dictionary<string, string>(),
|
||||||
_ => null
|
_ => null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue