Skip to content

Commit

Permalink
fix: fixed a bug where the installer would not detect existing app paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Nov 16, 2022
1 parent ad65f9f commit 8189d25
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Wolvenkit.Installer.Package/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="26499Wolvenkit.WolvenKit.Installer"
Publisher="[email protected], &quot;Open Source Developer, Moritz Baron&quot;, O=Open Source Developer, L=Gmunden, S=Oberösterreich, C=AT"
Version="0.1.2.0" />
Version="0.1.3.0" />

<Properties>
<DisplayName>WolvenKit.Installer</DisplayName>
Expand Down
3 changes: 1 addition & 2 deletions Wolvenkit.Installer/ItemTemplates.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
<RelativePanel
Grid.Row="1"
Grid.Column="1"
Grid.ColumnSpan="2"
Margin="16,6,0,0">

<TextBlock
Expand Down Expand Up @@ -205,7 +204,7 @@
VerticalAlignment="Center"
Style="{ThemeResource BaseTextBlockStyle}"
Text="Location: " />-->
<TextBox Text="{x:Bind InstallPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Text="{x:Bind InstallPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" />
<Button Margin="5,0,0,0" Command="{x:Bind PickFolderCommand}">
<SymbolIcon Symbol="Folder" />
</Button>
Expand Down
10 changes: 10 additions & 0 deletions Wolvenkit.Installer/Services/INotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface INotificationService

void CloseBanner();
void DisplayBanner(string title, string message, InfoBarSeverity severity);
void DisplayError(string message);


void StartIndeterminate();
Expand Down Expand Up @@ -50,6 +51,15 @@ public void DisplayBanner(string title, string message, InfoBarSeverity severity
BannerNotification.Title = title;
}

public void DisplayError(string message)
{
BannerNotification.IsOpen = true;

BannerNotification.Message = message;
BannerNotification.Severity = InfoBarSeverity.Error;
BannerNotification.Title = "Error";
}

public void CloseBanner() => BannerNotification.IsOpen = false;

public void StartIndeterminate() => Progress.IsIndeterminate = true;
Expand Down
5 changes: 3 additions & 2 deletions Wolvenkit.Installer/Services/LibraryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface ILibraryService

Task<string> GetLatestVersionAsync(RemotePackageModel model, bool prerelease);
Task<bool> InstallAsync(RemotePackageModel id, string installPath);
Task<bool> InstallAsync(PackageModel id);
Task<bool> InstallAsync(PackageModel id, string installPath);
Task InitAsync();
Task SaveAsync();
Task<bool> RemoveAsync(PackageModel model);
Expand Down Expand Up @@ -294,7 +294,8 @@ public async Task<bool> RemoveAsync(PackageModel model)
}
}

public async Task<bool> InstallAsync(PackageModel package) => TryGetRemote(package.Name, out var remote) && await InstallAsync(remote.GetModel(), remote.InstallPath);
public async Task<bool> InstallAsync(PackageModel package, string installPath)
=> TryGetRemote(package.Name, out var remote) && await InstallAsync(remote.GetModel(), installPath);

public async Task<bool> InstallAsync(RemotePackageModel package, string installPath)
{
Expand Down
93 changes: 59 additions & 34 deletions Wolvenkit.Installer/ViewModel/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,37 @@ private void Launch()
}
}

[RelayCommand()]
private async Task Uninstall()
private bool IsProcessRunning()
{
_notificationService.StartIndeterminate();
_notificationService.DisplayBanner("Uninstalling", $"Uninstalling {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational);
var pname = Process.GetProcessesByName("WolvenKit");
return pname is not null && pname.Length != 0;
}

private async Task<bool> UninstallModal()
{
var isuninstalled = false;

if (IsProcessRunning())
{
var dlg = new ContentDialog()
{
XamlRoot = App.MainRoot.XamlRoot,
Title = "Process running",
Content = $"Please close WolvenKit before continuing",
PrimaryButtonText = "Ok"
};

var r = await dlg.ShowAsync();

return false;
}

if (Directory.Exists(_model.Path))
{
// managed packages need confirmation
if (_model.Files is null || _model.Files.Length == 0)
{
var noWifiDialog = new ContentDialog()
var dlg = new ContentDialog()
{
XamlRoot = App.MainRoot.XamlRoot,
Title = "Remove",
Expand All @@ -126,17 +144,17 @@ private async Task Uninstall()
CloseButtonText = "Cancel"
};

var r = await noWifiDialog.ShowAsync();
var r = await dlg.ShowAsync();
if (r == ContentDialogResult.Primary)
{
try
{
Directory.Delete(_model.Path, true);
await _libraryService.RemoveAsync(_model);
isuninstalled = await _libraryService.RemoveAsync(_model);
}
catch (System.Exception)
catch (System.Exception e)
{
// todo logging
_notificationService.DisplayError(e.Message);
}
}
}
Expand All @@ -145,56 +163,63 @@ private async Task Uninstall()
try
{
Directory.Delete(_model.Path, true);
await _libraryService.RemoveAsync(_model);
isuninstalled = await _libraryService.RemoveAsync(_model);
}
catch (System.Exception)
catch (System.Exception e)
{
// todo logging
_notificationService.DisplayError(e.Message);
}
}
}

_notificationService.CloseBanner();
_notificationService.StopIndeterminate();
return isuninstalled;
}

[RelayCommand()]
private async Task Update()
private async Task Uninstall()
{
_notificationService.StartIndeterminate();
_notificationService.DisplayBanner("Updating", $"Updating {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational);
_notificationService.DisplayBanner("Uninstalling", $"Uninstalling {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational);

var isuninstalled = false;
if (await UninstallModal())
{
_notificationService.CloseBanner();
}

// remove
if (Directory.Exists(_model.Path))
_notificationService.StopIndeterminate();
}

[RelayCommand()]
private async Task Update()
{
if (IsProcessRunning())
{
try
var dlg = new ContentDialog()
{
Directory.Delete(_model.Path, true);
//foreach (var f in _model.Files)
//{
// File.Delete(f);
//}
XamlRoot = App.MainRoot.XamlRoot,
Title = "Process running",
Content = $"Please close WolvenKit before continuing",
PrimaryButtonText = "Ok"
};

var r = await dlg.ShowAsync();

isuninstalled = await _libraryService.RemoveAsync(_model);
}
catch (System.Exception)
{
// todo logging
}
return;
}

_notificationService.StartIndeterminate();
_notificationService.DisplayBanner("Updating", $"Updating {Name}. Please wait", Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational);

// install
if (isuninstalled)
if (await UninstallModal())
{
await _libraryService.InstallAsync(_model);
await _libraryService.InstallAsync(_model, _model.Path);
IsUpdateAvailable = false;
//.Height = s_expandedHeight;

_notificationService.CloseBanner();
}

_notificationService.CloseBanner();
_notificationService.StopIndeterminate();
}
}
Expand Down

0 comments on commit 8189d25

Please sign in to comment.