Menu

[r771]: / trunk / GoogleContactsSync / VersionInformation.cs  Maximize  Restore  History

Download this file

141 lines (129 with data), 5.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Runtime.InteropServices;
using System.Management;
using System.Threading.Tasks;
using System.Reflection;
using System.Diagnostics;
using System.Net.Http;
using System.Xml.Linq;
using System.Threading;
namespace GoContactSyncMod
{
static class VersionInformation
{
private const string DOWNLOADURL = "https://sourceforge.net/projects/googlesyncmod/files/latest/download";
private const string USERAGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0";
public enum OutlookMainVersion
{
Outlook2002,
Outlook2003,
Outlook2007,
Outlook2010,
Outlook2013,
Outlook2016,
OutlookUnknownVersion,
OutlookNoInstance
}
public static OutlookMainVersion GetOutlookVersion(Microsoft.Office.Interop.Outlook.Application appVersion)
{
if (appVersion == null)
appVersion = new Microsoft.Office.Interop.Outlook.Application();
switch (appVersion.Version.ToString().Substring(0, 2))
{
case "10":
return OutlookMainVersion.Outlook2002;
case "11":
return OutlookMainVersion.Outlook2003;
case "12":
return OutlookMainVersion.Outlook2007;
case "14":
return OutlookMainVersion.Outlook2010;
case "15":
return OutlookMainVersion.Outlook2013;
case "16":
return OutlookMainVersion.Outlook2016;
default:
{
if (appVersion != null)
{
Marshal.ReleaseComObject(appVersion);
GC.Collect();
GC.WaitForPendingFinalizers();
}
return OutlookMainVersion.OutlookUnknownVersion;
}
}
}
/// <summary>
/// detect windows main version
/// </summary>
public static string GetWindowsVersion()
{
try
{
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT Caption, OSArchitecture, Version FROM Win32_OperatingSystem"))
{
foreach (ManagementObject managementObject in searcher.Get())
{
string versionString = managementObject["Caption"].ToString() + " (" +
managementObject["OSArchitecture"].ToString() + "; " +
managementObject["Version"].ToString() + ")";
return versionString;
}
}
}
catch (Exception ex)
{
Logger.Log(ex, EventType.Debug);
}
return "Unknown Windows Version";
}
public static Version getGCSMVersion()
{
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
Version assemblyVersionNumber = new Version(fvi.FileVersion);
return assemblyVersionNumber;
}
public static async Task<bool> isNewVersionAvailable(CancellationToken cancellationToken)
{
Logger.Log("Reading version number from sf.net...", EventType.Information);
try
{
using (HttpClient client = new HttpClient())
{
var response = await client.GetAsync("https://sourceforge.net/projects/googlesyncmod/files/updates_v1.xml", HttpCompletionOption.ResponseHeadersRead, cancellationToken);
response.EnsureSuccessStatusCode();
var stream = await response.Content.ReadAsStreamAsync();
var doc = XDocument.Load(stream);
var strVersion = doc.Element("Version").Value;
if (!string.IsNullOrEmpty(strVersion))
{
var webVersionNumber = new Version(strVersion);
//compare both versions
var result = webVersionNumber.CompareTo(getGCSMVersion());
if (result > 0)
{ //newer version found
Logger.Log("New version of GCSM detected on sf.net!", EventType.Information);
return true;
}
else
{ //older or same version found
Logger.Log("Version of GCSM is uptodate.", EventType.Information);
return false;
}
}
else
return false;
}
}
catch (Exception ex)
{
Logger.Log("Could not read version number from sf.net...", EventType.Information);
Logger.Log(ex, EventType.Debug);
return false;
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.