forked from codeicon/disParity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Usage.cs
89 lines (79 loc) · 2.32 KB
/
Usage.cs
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
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using Microsoft.Win32;
using System.Threading;
using disParity;
namespace disParity.CmdLine
{
public class Usage
{
static string url;
static Thread thread;
static string shutdownMsg = "";
public static void Log(string msg)
{
bool firstRun;
if (NoPing())
return;
UInt32 id = GetID(out firstRun);
url = @"http://www.vilett.com/disParity/ping.php?cmd=" + msg + "&id=" +
id.ToString() + "&firstRun=" + (firstRun ? "1" : "0") +
"&ver=" + Version.VersionString;
thread = new Thread(GetURL);
thread.Start();
}
public static void GetURL()
{
try {
WebClient webClient = new WebClient();
byte[] buf = webClient.DownloadData(new System.Uri(url));
double currentVersion = Convert.ToDouble(Version.VersionNum);
double latestVersion = Convert.ToDouble(Encoding.ASCII.GetString(buf));
if (latestVersion > 0 && latestVersion > currentVersion)
shutdownMsg = "Note: Version " + Encoding.ASCII.GetString(buf) +
" of disParity is now available for download from www.vilett.com/disParity/\r\n";
}
catch {
return;
}
}
public static void Close()
{
if (shutdownMsg != "")
LogFile.Write(shutdownMsg);
if (thread != null && thread.IsAlive)
thread.Abort();
}
static UInt32 GetID(out bool firstRun)
{
firstRun = false;
try {
UInt32 id;
Object entry =
Registry.GetValue("HKEY_CURRENT_USER\\Software\\disParity", "ID", 0);
if (entry == null || (int)entry == 0) {
firstRun = true;
Random r = new Random();
id = (UInt32)r.Next();
Registry.SetValue("HKEY_CURRENT_USER\\Software\\disParity", "ID", id,
RegistryValueKind.DWord);
} else
id = (UInt32)(int)entry;
return id;
}
catch {
return 0;
}
}
static bool NoPing()
{
Object entry =
Registry.GetValue("HKEY_CURRENT_USER\\Software\\disParity", "noping", 0);
if (entry != null && (int)entry == 1)
return true;
return false;
}
}
}