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:
Robin Krom 2022-06-30 22:57:55 +02:00
parent 36a285ebd4
commit 48675b01f0
No known key found for this signature in database
GPG key ID: BCC01364F1371490
5 changed files with 121 additions and 79 deletions

View file

@ -388,26 +388,8 @@ namespace Greenshot.Base.Core
return ExperimentalFeatures != null && ExperimentalFeatures.Contains(experimentalFeature);
}
/// <summary>
/// Supply values we can't put as defaults
/// </summary>
/// <param name="property">The property to return a default for</param>
/// <returns>object with the default value for the supplied property</returns>
public override object GetDefault(string property)
private string CreateOutputFilePath()
{
switch (property)
{
case nameof(ExcludePlugins):
case nameof(IncludePlugins):
return new List<string>();
case nameof(OutputFileAsFullpath):
if (IniConfig.IsPortable)
{
return Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots\dummy.png");
}
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "dummy.png");
case nameof(OutputFilePath):
if (IniConfig.IsPortable)
{
string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots");
@ -420,8 +402,8 @@ namespace Greenshot.Base.Core
}
catch (Exception ex)
{
LOG.Warn(ex);
// Problem creating directory, fallback to Desktop
LOG.Warn(ex);
}
}
else
@ -431,45 +413,38 @@ namespace Greenshot.Base.Core
}
return Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
case nameof(DWMBackgroundColor):
return Color.Transparent;
case nameof(ActiveTitleFixes):
return new List<string>
}
/// <summary>
/// Supply values we can't put as defaults
/// </summary>
/// <param name="property">The property to return a default for</param>
/// <returns>object with the default value for the supplied property</returns>
public override object GetDefault(string property) =>
property switch
{
nameof(ExcludePlugins) => new List<string>(),
nameof(IncludePlugins) => 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"),
nameof(OutputFilePath) => CreateOutputFilePath(),
nameof(DWMBackgroundColor) => Color.Transparent,
nameof(ActiveTitleFixes) => new List<string> {
"Firefox",
"IE",
"Chrome"
},
nameof(TitleFixMatcher) => new Dictionary<string, string> {
{ "Firefox", " - Mozilla Firefox.*" },
{ "IE", " - (Microsoft|Windows) Internet Explorer.*" },
{ "Chrome", " - Google Chrome.*" }
},
nameof(TitleFixReplacer) => new Dictionary<string, string> {
{ "Firefox", string.Empty },
{ "IE", string.Empty },
{ "Chrome", string.Empty }
},
_ => null
};
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>
/// This method will be called before converting the property, making to possible to correct a certain value
@ -540,8 +515,9 @@ namespace Greenshot.Base.Core
OutputFileAutoReduceColors = false;
}
bool isUpgradeFrom12 = LastSaveWithVersion?.StartsWith("1.2") ?? false;
// Fix for excessive feed checking
if (UpdateCheckInterval != 0 && UpdateCheckInterval <= 7 && LastSaveWithVersion.StartsWith("1.2"))
if (UpdateCheckInterval != 0 && UpdateCheckInterval <= 7 && isUpgradeFrom12)
{
UpdateCheckInterval = 14;
}

View file

@ -21,6 +21,7 @@
using System;
using System.Windows.Forms;
using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.Box.Forms;
@ -75,5 +76,20 @@ namespace Greenshot.Plugin.Box
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;
}
}
}

View file

@ -21,6 +21,7 @@
using System;
using System.Windows.Forms;
using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.Dropbox.Forms;
@ -69,5 +70,20 @@ namespace Greenshot.Plugin.Dropbox
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;
}
}
}

View file

@ -20,6 +20,7 @@
*/
using System.Windows.Forms;
using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.Flickr.Forms;
@ -86,5 +87,21 @@ namespace Greenshot.Plugin.Flickr
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;
}
}
}

View file

@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Greenshot.Base.Core;
using Greenshot.Base.Core.Enums;
using Greenshot.Base.IniFile;
using Greenshot.Plugin.Imgur.Forms;
@ -84,6 +85,22 @@ namespace Greenshot.Plugin.Imgur
public Dictionary<string, ImgurInfo> runtimeImgurHistory = new Dictionary<string, ImgurInfo>();
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>
/// Supply values we can't put as defaults
/// </summary>
@ -92,7 +109,7 @@ namespace Greenshot.Plugin.Imgur
public override object GetDefault(string property) =>
property switch
{
"ImgurUploadHistory" => new Dictionary<string, string>(),
nameof(ImgurUploadHistory) => new Dictionary<string, string>(),
_ => null
};