Skip to content

Commit

Permalink
Update SelfUpdater for new packages
Browse files Browse the repository at this point in the history
  • Loading branch information
principis committed May 29, 2021
1 parent eef7c20 commit 3717fbe
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions tldr-sharp/SelfUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ internal static void CheckSelfUpdate()
if (updateQuestion.ReadAnswer() != YesNoAnswer.Yes) return;

Console.WriteLine("Select desired method:");
Console.WriteLine("0\tx86 Debian package (.deb)");
Console.WriteLine("1\tx64 Debian package (.deb)");
Console.WriteLine("0\tDebian package (.deb)");
Console.WriteLine("1\tRPM package (.rpm)");
Console.WriteLine("2\tinstall script (.sh)");

string option;
int optionNb;
do {
Console.Write("Enter number 0..3: ");
Console.Write("Enter number 0..2: ");
option = Console.ReadLine();
} while (!int.TryParse(option, out optionNb) || optionNb > 3 || optionNb < 0);

Expand All @@ -80,15 +80,16 @@ internal static void CheckSelfUpdate()
SelfUpdate(UpdateType.Debian, remoteVersion);
break;
case 1:
SelfUpdate(UpdateType.DebianX64, remoteVersion);
SelfUpdate(UpdateType.Rpm, remoteVersion);
break;
case 2:
SelfUpdate(UpdateType.Script, remoteVersion);
break;
}
}
else {
Console.WriteLine("Version {0} is available. Download it from {1}", remoteVersion, UpdateUrl);
Console.WriteLine("Version {0} is available. Download it from {1}", remoteVersion,
"https://github.com/principis/tldr-sharp/releases/");
}
}

Expand All @@ -113,20 +114,17 @@ private static void SelfUpdate(UpdateType type, Version version)
}
}

var startInfo = new ProcessStartInfo
{FileName = "/bin/bash", UseShellExecute = false, RedirectStandardOutput = true};

switch (type) {
case UpdateType.Debian:
case UpdateType.DebianX64:
startInfo.Arguments = "-c \"sudo dpkg -i " + tmpPath + "\"";
break;
case UpdateType.Script:
startInfo.Arguments = "-c \"bash " + tmpPath + "\"";
break;
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
var startInfo = new ProcessStartInfo {
FileName = "/bin/bash",
UseShellExecute = false,
RedirectStandardOutput = true,
Arguments = type switch {
UpdateType.Debian => "-c \"sudo dpkg -i " + tmpPath + "\"",
UpdateType.Rpm => "-c \"sudo rpm -i " + tmpPath + "\"",
UpdateType.Script => "-c \"bash " + tmpPath + "\"",
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
}
};

using (var process = new Process {StartInfo = startInfo}) {
process.Start();
Expand Down Expand Up @@ -156,7 +154,7 @@ private static string GetUpdateUrl(UpdateType type, Version version)

return type switch {
UpdateType.Debian => $"{downloadUrl}.deb",
UpdateType.DebianX64 => $"{downloadUrl}_x64.deb",
UpdateType.Rpm => $"{downloadUrl}rpm",
UpdateType.Script => ScriptUrl,
_ => null
};
Expand All @@ -165,7 +163,7 @@ private static string GetUpdateUrl(UpdateType type, Version version)
private enum UpdateType
{
Debian,
DebianX64,
Rpm,
Script
}
}
Expand Down

0 comments on commit 3717fbe

Please sign in to comment.