Skip to content

Commit

Permalink
- Fixed ModalDialog management during upgrade scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-shilo committed Apr 18, 2022
1 parent 8eec6cd commit 6900ac7
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 135 deletions.
15 changes: 6 additions & 9 deletions src/CSScriptNpp/CSScriptNpp/CSScriptHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ public static void Init()
syntaxer_asm = dependenciesDirRoot.PathJoin("cs-syntaxer", "syntaxer.dll");
syntaxer_port = 18001;

#if !DEBUG
if (!Directory.Exists(syntaxer_asm.GetDirName()))
#endif
DeployDir(Bootstrapper.pluginDir.PathJoin("cs-syntaxer"),
syntaxer_asm.GetDirName());
DeployDir(Bootstrapper.pluginDir.PathJoin("cs-syntaxer"),
syntaxer_asm.GetDirName());
}

if (!Config.Instance.UseEmbeddedEngine && Config.Instance.CustomEngineAsm.HasText())
Expand All @@ -52,11 +50,10 @@ public static void Init()
else
{
cscs_asm = dependenciesDirRoot.PathJoin("cs-script", "cscs.dll");
#if !DEBUG

if (!Directory.Exists(cscs_asm.GetDirName()))
#endif
DeployDir(Bootstrapper.pluginDir.PathJoin("cs-script"),
cscs_asm.GetDirName());
DeployDir(Bootstrapper.pluginDir.PathJoin("cs-script"),
cscs_asm.GetDirName());

var oldServicesVersions = Directory.GetDirectories(Path.GetDirectoryName(dependenciesDirRoot))
.Where(x => x != dependenciesDirRoot);
Expand Down Expand Up @@ -908,7 +905,7 @@ static void DownloadBinary(string url, string destinationPath, Action<long, long
throw new Exception($"Resource {url} cannot be downloaded.");
}

static string DownloadText(string url, string proxyUser = null, string proxyPw = null)
public static string DownloadText(this string url, string proxyUser = null, string proxyPw = null)
{
var sb = new StringBuilder();
byte[] buf = new byte[1024 * 4];
Expand Down
39 changes: 24 additions & 15 deletions src/CSScriptNpp/CSScriptNpp/Distro.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace CSScriptNpp
{
Expand All @@ -18,18 +9,36 @@ public class Distro
public string URL_root;
public string fullUrl;
public string ReleaseNotesText;
public string ReleaseNotesUrl;

public static Distro FromFixedLocation(string path)
{
return new Distro
// URL: https://github.com/oleg-shilo/cs-script.npp/releases/download/v2.0.0.0/CSScriptNpp.2.0.0.0.x64.zip
// URL: https://github.com/oleg-shilo/cs-script.npp/releases/download/v2.0.0.0/CSScriptNpp.2.0.0.0.ReleaseInfo.txt

var baseUrl = "https://github.com/oleg-shilo/cs-script.npp/releases/download/";

if (path.StartsWith(baseUrl))
{
fullUrl = path,
};
var tokens = path.Substring(baseUrl.Length).Split('/');

return new Distro
{
Version = tokens.FirstOrDefault()?.Replace("v", ""), // v1.1.1 vs 1.1.1
URL_root = baseUrl + tokens.FirstOrDefault(),
ReleaseNotesUrl = path.Replace(".x64.zip", ".ReleaseInfo.txt").Replace(".x86.zip", ".ReleaseInfo.txt")
};
}
else
return new Distro
{
fullUrl = path,
};
}

public static Distro FromVersionInfo(string info)
{
var lines = info.Trim().Replace("\r\n", "\n").Split(new[] { '\n' }, 3);

return new Distro
{
Version = lines[0].Replace("v", ""), // v1.1.1 vs 1.1.1
Expand All @@ -48,8 +57,8 @@ public string ZipUrl
get
{
return URL_root != null ?
URL_root + "/" + FileNameWithoutExtension + ".zip" :
fullUrl.ToUri();
URL_root + "/" + FileNameWithoutExtension + ".zip" :
fullUrl.ToUri();
}
}

Expand Down
12 changes: 8 additions & 4 deletions src/CSScriptNpp/Dialogs/ConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,17 @@ void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)

void update_Click(object sender, EventArgs e)
{
Dispatcher.Schedule(300, () =>
Close();
Task.Run(() =>
{
using (var dialog = new UpdateOptionsPanel(Distro.FromFixedLocation(customUpdateUrl.Text)))
Thread.Sleep(300);

var distro = Distro.FromFixedLocation(customUpdateUrl.Text);
using (var dialog = new UpdateOptionsPanel(distro))
{
dialog.ShowModal();
}
});

Close();
}

void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Expand Down
Loading

0 comments on commit 6900ac7

Please sign in to comment.