Skip to content

Commit

Permalink
check and download split
Browse files Browse the repository at this point in the history
  • Loading branch information
Etuldan committed Jan 31, 2023
1 parent ca985a0 commit 3f4b01b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
20 changes: 10 additions & 10 deletions GitHubdate/GitHubdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public GitHubdate(string Username, string Project, string InstallArguments = "",
_serviceGitHubInfo = new GitHubService(Username, Project);
}

private async Task DownloadAndInstall()
public async Task DownloadAndInstall()
{
var fullPath = Path.Combine(Path.GetTempPath(), _gitHubInformations.FileName);

Expand All @@ -45,7 +45,8 @@ private async Task DownloadAndInstall()
UseShellExecute = false,
FileName = fullPath,
WindowStyle = ProcessWindowStyle.Hidden,
Arguments = _installArguments
Arguments = _installArguments,
Verb = "runas"
};
try
{
Expand All @@ -60,36 +61,35 @@ private async Task DownloadAndInstall()
}
}

public async Task Check()
public async Task<bool> Check()
{
_gitHubInformations = await _serviceGitHubInfo.FetchInfo();
if( _gitHubInformations == null || _gitHubInformations.DownloadUrl == null || _gitHubInformations.FileName == null || _gitHubInformations.Version == null)
{
return;
return false;
}
if (_gitHubInformations.Version.CompareTo(_serviceLocalInfo.Version) > 0)
{
if (!_automaticUpdate)
{
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;

result = MessageBox.Show(
var buttons = MessageBoxButtons.YesNo;
var result = MessageBox.Show(
$"Current version: {_serviceLocalInfo.Version}\n" +
$"Available version: {_gitHubInformations.Version}\n\n" +
_gitHubInformations.Description,
$"Update available { _gitHubInformations.Name}",
buttons);
if (result == DialogResult.Yes)
{
await DownloadAndInstall();
return true;
}
}
else
{
await DownloadAndInstall();
return true;
}
}
return false;
}
}
}
8 changes: 6 additions & 2 deletions TestGitHubdate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ internal class Program
{
static async Task Main(string[] args)
{
var downloader = new GitHubdate.GitHubdate("Etuldan", "MidiControl", "/SILENT /NOCANCEL /NORESTART /FORCECLOSEAPPLICATIONS /SUPPRESSMSGBOXES", false);
await downloader.Check();
var downloader = new GitHubdate.GitHubdate("Etuldan", "GitHubdate");
var result = await downloader.Check();
if (result == true)
{
await downloader.DownloadAndInstall();
}
}
}

0 comments on commit 3f4b01b

Please sign in to comment.