-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
111 lines (107 loc) · 4.24 KB
/
Program.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Text.RegularExpressions;
using System.Net;
using System.Diagnostics;
using Newtonsoft.Json;
namespace rpcs3Updater
{
public class Program
{
static int percentage = 0;
public static void Main(string[] args)
{
Process[] pname = Process.GetProcessesByName("rpcs3");
if (File.Exists("RPCS3.log") & pname.Length == 0)
{
var getjson = _get_json_data<RootObject>("https://update.rpcs3.net/?c=somecommit"); //get json data from rpcs3 commit api using newtonsoft.json library
string windowsurl = getjson.latest_build.windows.download; //get the latest build url from json
string windowsdate = getjson.latest_build.windows.datetime;
string prnumber = getjson.latest_build.pr;
Match sversionmatch = Regex.Match(windowsurl, @"/artifacts/rpcs3-([^:]+)_win64.7z"); //use regex to get the server version.
Match lversionmatch = Regex.Match(File.ReadLines("RPCS3.log").First() , @"RPCS3 ([^:]+) Alpha"); //use regex to get local version id of rpcs3
string lversion = lversionmatch.Groups[1].Value.Remove(lversionmatch.Groups[1].Value.Length - 1); //delete the last char of local version
string sversion = sversionmatch.Groups[1].Value;
if (lversion == sversion) //if local version equals to server version
{
Console.WriteLine("RPCS3 is up to date");
}
else
{
Console.WriteLine("Your current version: " + lversion);
Console.WriteLine("RPCS3 is outdated, latest version available is: " + sversion ); //print the up to date version
Console.WriteLine("Date: " + windowsdate);
Console.WriteLine("PR number: " + prnumber);
Console.WriteLine("Do you want to download?(Y/n)");
string answer = Console.ReadLine();
if (answer == "y" || answer == "Y")
{
if (File.Exists("rpcs3Update.7z"))
{
File.Delete("rpcs3Update.7z");
}
using (WebClient wc = new WebClient())
{
wc.DownloadProgressChanged += wc_stringpercentage;
wc.DownloadFileAsync(new System.Uri(windowsurl), "rpcs3Update.7z"); //download latest build
while (percentage < 100)
{
string message = "Downloading rpcs3 archive for updating: ";
Console.Write("\r{0}{1}% complete.",message, percentage);
}
}
Console.WriteLine(" ");
if (percentage == 100)
{
Console.WriteLine("File downloaded succesfully, extracting rpcs3.exe");
File.Move("rpcs3.exe", "rpcs3.exe.oldversion");
try
{
ProcessStartInfo process = new ProcessStartInfo();
process.WindowStyle = ProcessWindowStyle.Hidden;
process.FileName = "7zr.exe"; //use 7zip to extract rpcs3.exe
process.Arguments = "e rpcs3Update.7z rpcs3.exe";
Process p = Process.Start(process);
p.WaitForExit();
}
catch (System.Exception Ex)
{
}
File.Delete("rpcs3Update.7z");
}
Console.WriteLine("Done!");
}
}
Console.WriteLine("Press a key to close...");
Console.ReadKey();
}
else
{
Console.WriteLine("RPCS3.log couldn't found! Copy this executable to rpcs3 directory or close RPCS3.");
Console.WriteLine("Press a key to close...");
Console.ReadKey();
}
}
static void wc_stringpercentage(object sender, DownloadProgressChangedEventArgs e)
{
percentage = e.ProgressPercentage;
}
public static T _get_json_data<T>(string url) where T : new()
{
using (var w = new WebClient())
{
var json_data = string.Empty;
try
{
json_data = w.DownloadString(url);
}
catch (Exception) { }
return !string.IsNullOrEmpty(json_data) ? JsonConvert.DeserializeObject<T>(json_data) : new T();
}
}
}
}