-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2191 from louislam/exe
Windows Executable File - uptime-kuma.exe
- Loading branch information
Showing
22 changed files
with
1,594 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
|
||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Diagnostics.Tracing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Reflection" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Runtime.InteropServices" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using Newtonsoft.Json; | ||
|
||
namespace UptimeKuma { | ||
public partial class DownloadForm : Form { | ||
private readonly Queue<DownloadItem> downloadQueue = new(); | ||
private readonly WebClient webClient = new(); | ||
private DownloadItem currentDownloadItem; | ||
|
||
public DownloadForm() { | ||
InitializeComponent(); | ||
} | ||
|
||
private void DownloadForm_Load(object sender, EventArgs e) { | ||
webClient.DownloadProgressChanged += DownloadProgressChanged; | ||
webClient.DownloadFileCompleted += DownloadFileCompleted; | ||
|
||
label.Text = "Reading latest version..."; | ||
|
||
// Read json from https://uptime.kuma.pet/version | ||
var versionJson = new WebClient().DownloadString("https://uptime.kuma.pet/version"); | ||
var versionObj = JsonConvert.DeserializeObject<Version>(versionJson); | ||
|
||
var nodeVersion = versionObj.nodejs; | ||
var uptimeKumaVersion = versionObj.latest; | ||
var hasUpdateFile = File.Exists("update"); | ||
|
||
if (!Directory.Exists("node")) { | ||
downloadQueue.Enqueue(new DownloadItem { | ||
URL = $"https://nodejs.org/dist/v{nodeVersion}/node-v{nodeVersion}-win-x64.zip", | ||
Filename = "node.zip", | ||
TargetFolder = "node" | ||
}); | ||
} | ||
|
||
if (!Directory.Exists("core") || hasUpdateFile) { | ||
|
||
// It is update, rename the core folder to core.old | ||
if (Directory.Exists("core")) { | ||
// Remove the old core.old folder | ||
if (Directory.Exists("core.old")) { | ||
Directory.Delete("core.old", true); | ||
} | ||
|
||
Directory.Move("core", "core.old"); | ||
} | ||
|
||
downloadQueue.Enqueue(new DownloadItem { | ||
URL = $"https://github.com/louislam/uptime-kuma/archive/refs/tags/{uptimeKumaVersion}.zip", | ||
Filename = "core.zip", | ||
TargetFolder = "core" | ||
}); | ||
|
||
File.WriteAllText("version.json", versionJson); | ||
|
||
// Delete the update file | ||
if (hasUpdateFile) { | ||
File.Delete("update"); | ||
} | ||
} | ||
|
||
DownloadNextFile(); | ||
} | ||
|
||
void DownloadNextFile() { | ||
if (downloadQueue.Count > 0) { | ||
var item = downloadQueue.Dequeue(); | ||
|
||
currentDownloadItem = item; | ||
|
||
// Download if the zip file is not existing | ||
if (!File.Exists(item.Filename)) { | ||
label.Text = item.URL; | ||
webClient.DownloadFileAsync(new Uri(item.URL), item.Filename); | ||
} else { | ||
progressBar.Value = 100; | ||
label.Text = "Use local " + item.Filename; | ||
DownloadFileCompleted(null, null); | ||
} | ||
} else { | ||
npmSetup(); | ||
} | ||
} | ||
|
||
void npmSetup() { | ||
labelData.Text = ""; | ||
|
||
var npm = "..\\node\\npm.cmd"; | ||
var cmd = $"{npm} ci --production & {npm} run download-dist & exit"; | ||
|
||
var startInfo = new ProcessStartInfo { | ||
FileName = "cmd.exe", | ||
Arguments = $"/k \"{cmd}\"", | ||
RedirectStandardOutput = false, | ||
RedirectStandardError = false, | ||
RedirectStandardInput = true, | ||
UseShellExecute = false, | ||
CreateNoWindow = false, | ||
WorkingDirectory = "core" | ||
}; | ||
|
||
var process = new Process(); | ||
process.StartInfo = startInfo; | ||
process.EnableRaisingEvents = true; | ||
process.Exited += (_, e) => { | ||
progressBar.Value = 100; | ||
|
||
if (process.ExitCode == 0) { | ||
Task.Delay(2000).ContinueWith(_ => { | ||
Application.Restart(); | ||
}); | ||
label.Text = "Done"; | ||
} else { | ||
label.Text = "Failed, exit code: " + process.ExitCode; | ||
} | ||
|
||
}; | ||
process.Start(); | ||
label.Text = "Installing dependencies and download dist files"; | ||
progressBar.Value = 50; | ||
process.WaitForExit(); | ||
} | ||
|
||
void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { | ||
progressBar.Value = e.ProgressPercentage; | ||
var total = e.TotalBytesToReceive / 1024; | ||
var current = e.BytesReceived / 1024; | ||
|
||
if (total > 0) { | ||
labelData.Text = $"{current}KB/{total}KB"; | ||
} | ||
} | ||
|
||
void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { | ||
Extract(currentDownloadItem); | ||
DownloadNextFile(); | ||
} | ||
|
||
void Extract(DownloadItem item) { | ||
if (Directory.Exists(item.TargetFolder)) { | ||
var dir = new DirectoryInfo(item.TargetFolder); | ||
dir.Delete(true); | ||
} | ||
|
||
if (Directory.Exists("temp")) { | ||
var dir = new DirectoryInfo("temp"); | ||
dir.Delete(true); | ||
} | ||
|
||
labelData.Text = $"Extracting {item.Filename}..."; | ||
|
||
ZipFile.ExtractToDirectory(item.Filename, "temp"); | ||
|
||
string[] dirList; | ||
|
||
// Move to the correct level | ||
dirList = Directory.GetDirectories("temp"); | ||
|
||
|
||
|
||
if (dirList.Length > 0) { | ||
var dir = dirList[0]; | ||
|
||
// As sometime ExtractToDirectory is still locking the directory, loop until ok | ||
while (true) { | ||
try { | ||
Directory.Move(dir, item.TargetFolder); | ||
break; | ||
} catch (Exception exception) { | ||
Thread.Sleep(1000); | ||
} | ||
} | ||
|
||
} else { | ||
MessageBox.Show("Unexcepted Error: Cannot move extracted files, folder not found."); | ||
} | ||
|
||
labelData.Text = $"Extracted"; | ||
|
||
if (Directory.Exists("temp")) { | ||
var dir = new DirectoryInfo("temp"); | ||
dir.Delete(true); | ||
} | ||
|
||
File.Delete(item.Filename); | ||
} | ||
} | ||
|
||
public class DownloadItem { | ||
public string URL { get; set; } | ||
public string Filename { get; set; } | ||
public string TargetFolder { get; set; } | ||
} | ||
} | ||
|
Oops, something went wrong.