Skip to content

Commit

Permalink
fix package install
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Sep 9, 2023
1 parent c53dc8d commit bb7cb93
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build/props/Dock.Avalonia.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="Dock.Avalonia" Version="11.0.0"/>
<PackageReference Include="Dock.Model.Mvvm" Version="11.0.0"/>
<PackageReference Include="Dock.Avalonia" Version="11.0.0.2"/>
<PackageReference Include="Dock.Model.Mvvm" Version="11.0.0.2"/>
</ItemGroup>
</Project>
49 changes: 49 additions & 0 deletions src/OneWare.Core/Services/Paths.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using OneWare.Shared.Extensions;
using OneWare.Shared.Services;
using Prism.Ioc;

namespace OneWare.Core.Services;

Expand All @@ -11,6 +14,8 @@ public class Paths : IPaths
public string AppDataDirectory =>
Path.Combine(Environment.GetFolderPath(RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? Environment.SpecialFolder.LocalApplicationData : Environment.SpecialFolder.ApplicationData), AppFolderName);
public string TempDirectory => Path.GetTempPath();

public string SessionDirectory { get; }
public string LayoutDirectory => Path.Combine(AppDataDirectory, "Layouts");
public string SettingsPath => Path.Combine(AppDataDirectory, "Settings.json");
public string DocumentsDirectory =>
Expand All @@ -32,5 +37,49 @@ public Paths(string appName, string appIconPath)
Directory.CreateDirectory(CrashReportsDirectory);
Directory.CreateDirectory(ProjectsDirectory);
//...

var sessionsDir = Path.Combine(TempDirectory, "OneWare", "Sessions");
CleanupSessions(sessionsDir);

SessionDirectory = Path.Combine(sessionsDir, "OneWareStudioSession").CheckNameDirectory();
Directory.CreateDirectory(SessionDirectory);

//Lock file
File.Create(Path.Combine(SessionDirectory, ".session_lock"));
}

private static void CleanupSessions(string sessionsDir)
{
//Cleanup
try
{
if (Directory.Exists(sessionsDir))
{
var sessionFolders = Directory.GetDirectories(sessionsDir);

foreach (var session in sessionFolders)
{
var lockFilePath = Path.Combine(session, ".session_lock");
var fileInfo = new FileInfo(lockFilePath);

try
{
using (var stream = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.None))
{
stream.Close();
}
Directory.Delete(session, true);
}
catch(Exception e)
{
Debug.Write(e.Message);
}
}
}
}
catch (Exception e)
{
Debug.Write(e.Message);
}
}
}
7 changes: 4 additions & 3 deletions src/OneWare.Core/Services/PluginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using OneWare.Shared.Helpers;
using OneWare.Shared.Models;
using OneWare.Shared.Services;
using Prism.Ioc;
using Prism.Modularity;

namespace OneWare.Core.Services;
Expand All @@ -11,7 +12,7 @@ public class PluginService : IPluginService
private readonly IModuleCatalog _moduleCatalog;
private readonly IModuleManager _moduleManager;
private readonly IPaths _paths;

private readonly string _pluginDirectory;
private readonly Dictionary<string, string> _plugins = new();

Expand All @@ -22,8 +23,8 @@ public PluginService(IModuleCatalog moduleCatalog, IModuleManager moduleManager,
_moduleCatalog = moduleCatalog;
_moduleManager = moduleManager;
_paths = paths;

_pluginDirectory = Path.Combine(paths.TempDirectory, "OneWare Modules").CheckNameDirectory();
_pluginDirectory = Path.Combine(_paths.SessionDirectory, "Plugins");
Directory.CreateDirectory(_pluginDirectory);
}

Expand Down
15 changes: 14 additions & 1 deletion src/OneWare.PackageManager/ViewModels/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public PackageStatus Status
PackageStatus.Installing => "Cancel",
PackageStatus.Unavailable => "Unavailable"
};
PrimaryButtonEnabled = value is PackageStatus.Available or PackageStatus.Installed;
}
}

Expand All @@ -62,6 +63,13 @@ public string PrimaryButtonText
set => SetProperty(ref _primaryButtonText, value);
}

private bool _primaryButtonEnabled = false;
public bool PrimaryButtonEnabled
{
get => _primaryButtonEnabled;
set => SetProperty(ref _primaryButtonEnabled, value);
}

public PackageViewModel(Package package, IHttpService httpService, IPaths paths, ILogger logger, IPluginService pluginService)
{
Package = package;
Expand Down Expand Up @@ -118,10 +126,12 @@ public async Task ResolveAsync(CancellationToken cancellationToken)
SelectedVersion = Package.Versions?.LastOrDefault();
}

public async Task InstallAsync()
private async Task InstallAsync()
{
try
{
Status = PackageStatus.Installing;

var currentTarget = PlatformHelper.Platform.ToString().ToLower();

var target = Package.Versions?
Expand Down Expand Up @@ -151,6 +161,7 @@ public async Task InstallAsync()
catch (Exception e)
{
_logger.Error(e.Message, e);
Status = PackageStatus.Available;
}
}

Expand All @@ -159,5 +170,7 @@ public async Task RemoveAsync()
if (Package.Id == null) throw new NullReferenceException(nameof(Package.Id));
_pluginService.RemovePlugin(Package.Id!);
Status = PackageStatus.Available;
PrimaryButtonEnabled = false;
PrimaryButtonText = "Restart Required";
}
}
3 changes: 2 additions & 1 deletion src/OneWare.PackageManager/Views/PackageManagerView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
<StackPanel Grid.Row="0" Grid.Column="1" Spacing="5" Orientation="Horizontal">
<TextBlock Text="{Binding SelectedVersion.Version}" Foreground="{DynamicResource ThemeForegroundLowBrush}"/>
<Button Content="{Binding PrimaryButtonText}"
Classes="RoundButton" Command="{Binding ExecuteMainButtonAsync }"/>
Classes="RoundButton" Command="{Binding ExecuteMainButtonAsync}"
IsEnabled="{Binding PrimaryButtonEnabled}" />
</StackPanel>
</Grid>
</DockPanel>
Expand Down
5 changes: 2 additions & 3 deletions src/OneWare.PackageManager/Views/PackageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
</ComboBox>
</Border>

<Button Content="{Binding PrimaryButtonText}" Classes="RoundButton" Command="{Binding ExecuteMainButtonAsync }"/>

<TextBlock Text="Status" VerticalAlignment="Center"></TextBlock>
<Button Content="{Binding PrimaryButtonText}" IsEnabled="{Binding PrimaryButtonEnabled}"
Classes="RoundButton" Command="{Binding ExecuteMainButtonAsync }"/>
</StackPanel>

<ItemsControl ItemsSource="{Binding SelectedVersion.Targets}">
Expand Down
1 change: 1 addition & 0 deletions src/OneWare.Shared/Services/IPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IPaths
public string AppFolderName { get; }
public string AppDataDirectory { get; }
public string TempDirectory { get; }
public string SessionDirectory { get; }
public string LayoutDirectory { get; }
public string SettingsPath { get; }
public string DocumentsDirectory { get; }
Expand Down

0 comments on commit bb7cb93

Please sign in to comment.