Menu

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

Download this file

140 lines (126 with data), 5.3 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
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Management;
using System.Management.Instrumentation;
using System.Net;
using System.Threading.Tasks;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
using System.Globalization;
namespace GoContactSyncMod
{
static class VersionInformation
{
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()
{
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_OperatingSystem"))
{
foreach (ManagementObject managementObject in searcher.Get())
{
string versionString = managementObject["Caption"].ToString() + " (" +
managementObject["OSArchitecture"].ToString() + "; " +
managementObject["Version"].ToString() + ")";
return versionString;
}
}
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;
}
/// <summary>
/// getting the newest availible version on sourceforge.net of GCSM
/// </summary>
public static bool isNewVersionAvailable()
{
Logger.Log("Reading version number from sf.net...", EventType.Information);
try
{
//check sf.net site for version number
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://sourceforge.net/projects/googlesyncmod/files/latest/download");
request.AllowAutoRedirect = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
request.Abort();
//extracting version number from url
const string firstPattern = "Releases/";
// ex. /project/googlesyncmod/Releases/3.9.5/SetupGCSM-3.9.5.msi
string webVersion = response.ResponseUri.AbsolutePath;
//get version number string
int first = webVersion.IndexOf(firstPattern) + firstPattern.Length;
int second = webVersion.IndexOf("/", first);
Version webVersionNumber = new Version(webVersion.Substring(first, second - first));
response.Close();
//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;
}
}
catch (Exception ex)
{
Logger.Log("Could not read version number from sf.net...", EventType.Warning);
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.