Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
better installation warning and version 9
Browse files Browse the repository at this point in the history
  • Loading branch information
byCrookie committed Feb 17, 2023
1 parent 6c22918 commit f2ab5db
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<MajorVersion>1</MajorVersion>
<MinorVersion>1</MinorVersion>
<PatchVersion>8</PatchVersion>
<PatchVersion>9</PatchVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ public ModalParameter()
Buttons = ModalButtons.Ok;
OnOkAsync = () => Task.CompletedTask;
OnCancelAsync = () => Task.CompletedTask;
OkText = "Ok";
CancelText = "Cancel";
}

public string? Title { get; set; }
public string? Text { get; set; }
public ModalButtons Buttons { get; set; }
public Func<Task> OnOkAsync { get; set; }
public string OkText { get; set; }
public string CancelText { get; set; }
public Func<Task> OnCancelAsync { get; set; }
}
4 changes: 2 additions & 2 deletions src/TypeCode.Wpf/Helper/Navigation/Modal/View/ModalView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
Visibility="{Binding OkVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
Background="{StaticResource Primary}"
BorderBrush="{StaticResource Secondary}"
Content="Cancel" />
Content="{Binding CancelText}" />

<Button Margin="5,5,0,0" Grid.Row="2" Grid.Column="2"
Command="{Binding OkCommand}"
Visibility="{Binding OkVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
BorderBrush="{StaticResource Secondary}"
Content="Ok" />
Content="{Binding OkText}" />
</Grid>
</Border>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public Task OnNavigatedToAsync(NavigationContext context)
Title = parameter.Title;
Text = parameter.Text;
OkVisible = parameter.Buttons is ModalButtons.Ok or ModalButtons.OkAndCancel;
OkText = parameter.OkText;
CancelVisible = parameter.Buttons is ModalButtons.OkAndCancel;
CancelText = parameter.CancelText;
return Task.CompletedTask;
}

Expand All @@ -44,9 +46,15 @@ private Task CancelAsync()
[ObservableProperty]
private string? _text;

[ObservableProperty]
private string? _okText;

[ObservableProperty]
private bool _okVisible;

[ObservableProperty]
private string? _cancelText;

[ObservableProperty]
private bool _cancelVisible;
}
86 changes: 50 additions & 36 deletions src/TypeCode.Wpf/Main/Content/MainContentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,54 +83,68 @@ private Task UpdateAsync()

return _modalNavigationService.OpenModalAsync(new ModalParameter
{
Title = "WARNING - Update (Installer)",
Text = "The installer uses the location of the current version of TypeCode to install the update." +
" You can change the installation path (destination folder) in the advanced menu of the install wizard.",
OnOkAsync = async () =>
Title = "WARNING - Installation Source",
Text = "Only continue installing if you have installed the program directly from github. Do not continue if you have used winget" +
" or any other way of installing." +
$"{Environment.NewLine}- If you have used winget use the winget update commands." +
$"{Environment.NewLine}- If you have used another tool to install typecode, use it again to update.",
Buttons = ModalButtons.OkAndCancel,
OkText = "I have installed typecode directly from github previously!",
OnOkAsync = () => _modalNavigationService.OpenModalAsync(new ModalParameter
{
IsBannerVisible = false;

var name = $"TypeCode.Wpf.Setup_{_version?.NewVersion}";
Title = "WARNING - Update (Installer)",
Text = "The installer uses the location of the current version of TypeCode to install the update." +
" You can change the installation path (destination folder) in the advanced menu of the install wizard.",
OnOkAsync = () =>
{
IsBannerVisible = false;
return InstallMsiAsync();
}
})
});
}

var url = $"https://github.com/byCrookie/TypeCode/releases/download/{_version?.NewVersion}/{name}.msi";
var executingLocation = Path.GetDirectoryName(AppContext.BaseDirectory) ?? throw new Exception();
private async Task InstallMsiAsync()
{
const string name = "TypeCode.Wpf.Setup.msi";

var msi = Path.Combine(executingLocation, $"{name}.msi");
var url = $"https://github.com/byCrookie/TypeCode/releases/download/{_version?.NewVersion}/{name}";
var executingLocation = Path.GetDirectoryName(AppContext.BaseDirectory) ?? throw new Exception();

if (File.Exists(msi))
{
File.Delete(msi);
}
var msi = Path.Combine(executingLocation, name);

using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("User-Agent", "byCrookie");
if (File.Exists(msi))
{
File.Delete(msi);
}

var uri = new Uri(url);
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("User-Agent", "byCrookie");

var response = await client.GetAsync(uri).ConfigureAwait(true);
var uri = new Uri(url);

if (!response.IsSuccessStatusCode)
{
throw new Exception("Error retrieving update package");
}
var response = await client.GetAsync(uri).ConfigureAwait(true);

var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(true);
if (!response.IsSuccessStatusCode)
{
throw new Exception("Error retrieving update package");
}

await using (var fileStream = new FileStream(msi, FileMode.Create))
{
await stream.CopyToAsync(fileStream).ConfigureAwait(true);
}
}
var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(true);

var process = new Process();
process.StartInfo.FileName = "msiexec";
process.StartInfo.Arguments = $" /i {msi} APPLICATIONFOLDER={executingLocation}";
process.StartInfo.Verb = "runas";
process.Start();
Environment.Exit(0);
await using (var fileStream = new FileStream(msi, FileMode.Create))
{
await stream.CopyToAsync(fileStream).ConfigureAwait(true);
}
});
}

var process = new Process();
process.StartInfo.FileName = "msiexec";
process.StartInfo.Arguments = $" /i {msi} APPLICATIONFOLDER={executingLocation}";
process.StartInfo.Verb = "runas";
process.Start();
Environment.Exit(0);
}

[ObservableProperty]
Expand Down

0 comments on commit f2ab5db

Please sign in to comment.