mirror of
https://github.com/ShareX/ShareX.git
synced 2024-10-02 18:26:27 +13:00
SettingsBase first time run and previous version check support
This commit is contained in:
parent
61614935d2
commit
64c4c79755
7 changed files with 73 additions and 41 deletions
|
@ -335,6 +335,29 @@ public static void OpenFolderWithFile(string filePath)
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If version1 newer than version2 = 1
|
||||
/// If version1 equal to version2 = 0
|
||||
/// If version1 older than version2 = -1
|
||||
/// </summary>
|
||||
public static int CompareVersion(string version1, string version2)
|
||||
{
|
||||
return NormalizeVersion(version1).CompareTo(NormalizeVersion(version2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If version newer than ApplicationVersion = 1
|
||||
/// If version equal to ApplicationVersion = 0
|
||||
/// If version older than ApplicationVersion = -1
|
||||
/// </summary>
|
||||
public static int CompareApplicationVersion(string version)
|
||||
{
|
||||
return CompareVersion(version, Application.ProductVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If latestVersion newer than currentVersion = true
|
||||
/// </summary>
|
||||
public static bool CheckVersion(Version currentVersion, Version latestVersion)
|
||||
{
|
||||
return NormalizeVersion(latestVersion).CompareTo(NormalizeVersion(currentVersion)) > 0;
|
||||
|
@ -345,6 +368,11 @@ private static Version NormalizeVersion(Version version)
|
|||
return new Version(Math.Max(version.Major, 0), Math.Max(version.Minor, 0), Math.Max(version.Build, 0), Math.Max(version.Revision, 0));
|
||||
}
|
||||
|
||||
private static Version NormalizeVersion(string version)
|
||||
{
|
||||
return NormalizeVersion(Version.Parse(version));
|
||||
}
|
||||
|
||||
public static bool IsWindowsXP()
|
||||
{
|
||||
return OSVersion.Major == 5 && OSVersion.Minor == 1;
|
||||
|
|
|
@ -37,11 +37,26 @@ namespace HelpersLib
|
|||
{
|
||||
public static readonly SerializationType SerializationType = SerializationType.Json;
|
||||
|
||||
[Browsable(false), XmlIgnore, JsonIgnore]
|
||||
public string FilePath { get; private set; }
|
||||
|
||||
public string ApplicationVersion { get; set; }
|
||||
|
||||
public bool IsFirstTimeRun
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.IsNullOrEmpty(ApplicationVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPreviousVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return !IsFirstTimeRun && Helpers.CompareApplicationVersion(ApplicationVersion) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static T Load(string filePath)
|
||||
{
|
||||
T setting = SettingsHelper.Load<T>(filePath, SerializationType);
|
||||
|
@ -55,11 +70,11 @@ public static T Load(Stream stream)
|
|||
return setting;
|
||||
}
|
||||
|
||||
public virtual bool Save(string filePath)
|
||||
public bool Save(string filePath)
|
||||
{
|
||||
FilePath = filePath;
|
||||
ApplicationVersion = Application.ProductVersion;
|
||||
return SettingsHelper.Save(this, filePath, SerializationType);
|
||||
return SettingsHelper.Save(this, FilePath, SerializationType);
|
||||
}
|
||||
|
||||
private void Save()
|
||||
|
@ -77,7 +92,7 @@ private void SaveAsync()
|
|||
SaveAsync(FilePath);
|
||||
}
|
||||
|
||||
public virtual void Save(Stream stream)
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
SettingsHelper.Save(this, stream, SerializationType);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace HelpersLib
|
||||
{
|
||||
|
@ -37,6 +38,7 @@ public abstract class UpdateChecker
|
|||
|
||||
public UpdateChecker()
|
||||
{
|
||||
CurrentVersion = Version.Parse(Application.ProductVersion);
|
||||
ReleaseType = ReleaseChannelType.Stable;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace HelpersLib
|
||||
{
|
||||
|
@ -65,8 +66,13 @@ public UpdateInfo()
|
|||
|
||||
public void RefreshStatus()
|
||||
{
|
||||
if (Status != UpdateStatus.UpdateCheckFailed && CurrentVersion != null && LatestVersion != null &&
|
||||
!string.IsNullOrEmpty(DownloadURL) && (forceUpdate || Helpers.CheckVersion(CurrentVersion, LatestVersion)))
|
||||
if (CurrentVersion == null)
|
||||
{
|
||||
CurrentVersion = Version.Parse(Application.ProductVersion);
|
||||
}
|
||||
|
||||
if (Status != UpdateStatus.UpdateCheckFailed && CurrentVersion != null && LatestVersion != null && !string.IsNullOrEmpty(DownloadURL) &&
|
||||
(forceUpdate || Helpers.CheckVersion(CurrentVersion, LatestVersion)))
|
||||
{
|
||||
Status = UpdateStatus.UpdateAvailable;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ public UploadTestForm()
|
|||
|
||||
if (string.IsNullOrEmpty(TestText))
|
||||
{
|
||||
TestText = Program.ApplicationName + " text upload test";
|
||||
TestText = "ShareX text upload test";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(TestURL))
|
||||
|
|
|
@ -39,47 +39,18 @@ namespace ShareX
|
|||
{
|
||||
internal static class Program
|
||||
{
|
||||
public static readonly string ApplicationName = Application.ProductName;
|
||||
public static readonly Version AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
|
||||
public static string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
string title = string.Format("{0} {1}.{2}", ApplicationName, AssemblyVersion.Major, AssemblyVersion.Minor);
|
||||
if (AssemblyVersion.Build > 0) title += "." + AssemblyVersion.Build;
|
||||
if (IsPortable) title += " Portable";
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
public static string AssemblyCopyright
|
||||
{
|
||||
get
|
||||
{
|
||||
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
|
||||
|
||||
if (attributes.Length == 0)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
|
||||
}
|
||||
}
|
||||
|
||||
#region Paths
|
||||
|
||||
public static readonly string StartupPath = Application.StartupPath;
|
||||
|
||||
public static readonly string DefaultPersonalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ApplicationName);
|
||||
private static readonly string PortablePersonalPath = Path.Combine(StartupPath, ApplicationName);
|
||||
public static readonly string DefaultPersonalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "ShareX");
|
||||
private static readonly string PortablePersonalPath = Path.Combine(StartupPath, "ShareX");
|
||||
private static readonly string PersonalPathConfig = Path.Combine(StartupPath, "PersonalPath.cfg");
|
||||
private static readonly string ApplicationConfigFilename = "ApplicationConfig.json";
|
||||
private static readonly string UploadersConfigFilename = "UploadersConfig.json";
|
||||
private static readonly string HotkeysConfigFilename = "HotkeysConfig.json";
|
||||
private static readonly string HistoryFilename = "History.xml";
|
||||
private static readonly string LogFileName = ApplicationName + "-Log-{0:yyyy-MM}.txt";
|
||||
private static readonly string LogFileName = "ShareX-Log-{0:yyyy-MM}.txt";
|
||||
|
||||
public static string CustomPersonalPath { get; private set; }
|
||||
|
||||
|
@ -242,6 +213,18 @@ public static string ToolsFolder
|
|||
|
||||
#endregion Paths
|
||||
|
||||
public static string Title
|
||||
{
|
||||
get
|
||||
{
|
||||
Version version = Version.Parse(Application.ProductVersion);
|
||||
string title = string.Format("ShareX {0}.{1}", version.Major, version.Minor);
|
||||
if (version.Build > 0) title += "." + version.Build;
|
||||
if (IsPortable) title += " Portable";
|
||||
return title;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsMultiInstance { get; private set; }
|
||||
public static bool IsPortable { get; private set; }
|
||||
public static bool IsSilentRun { get; private set; }
|
||||
|
|
|
@ -395,7 +395,6 @@ public static Icon GetProgressIcon(int percentage)
|
|||
public static UpdateChecker CheckUpdate()
|
||||
{
|
||||
UpdateChecker updateChecker = new GitHubUpdateChecker("ShareX", "ShareX");
|
||||
updateChecker.CurrentVersion = Program.AssemblyVersion;
|
||||
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||
updateChecker.CheckUpdate();
|
||||
|
||||
|
@ -403,7 +402,6 @@ public static UpdateChecker CheckUpdate()
|
|||
if (updateChecker.UpdateInfo == null || updateChecker.UpdateInfo.Status == UpdateStatus.UpdateCheckFailed)
|
||||
{
|
||||
updateChecker = new XMLUpdateChecker("http://getsharex.com/Update.xml", "ShareX");
|
||||
updateChecker.CurrentVersion = Program.AssemblyVersion;
|
||||
updateChecker.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||
updateChecker.CheckUpdate();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue