mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add enable portable mode logic
This commit is contained in:
parent
56c2964e96
commit
7385243c1d
6 changed files with 97 additions and 2 deletions
13
Wox.Core/Configuration/IPortable.cs
Normal file
13
Wox.Core/Configuration/IPortable.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
namespace Wox.Core.Configuration
|
||||
{
|
||||
public interface IPortable
|
||||
{
|
||||
void EnablePortableMode();
|
||||
void DisablePortableMode();
|
||||
void RemoveShortcuts();
|
||||
void RemoveUninstallerEntry();
|
||||
bool IsPortableModeEnabled();
|
||||
void MoveUserDataFolder(string fromLocation, string toLocation);
|
||||
}
|
||||
}
|
||||
68
Wox.Core/Configuration/Portable.cs
Normal file
68
Wox.Core/Configuration/Portable.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using Squirrel;
|
||||
using System;
|
||||
using Wox.Infrastructure;
|
||||
|
||||
namespace Wox.Core.Configuration
|
||||
{
|
||||
public class Portable : IPortable
|
||||
{
|
||||
private string applicationName;
|
||||
private string exeName;
|
||||
private string rootAppDirectory;
|
||||
private UpdateManager portabilityUpdater;
|
||||
|
||||
public Portable()
|
||||
{
|
||||
applicationName = Constant.Wox;
|
||||
exeName = applicationName + ".exe";
|
||||
rootAppDirectory = Constant.RootDirectory;
|
||||
portabilityUpdater = new UpdateManager(string.Empty, applicationName, rootAppDirectory);
|
||||
}
|
||||
|
||||
public void DisablePortableMode()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void EnablePortableMode()
|
||||
{
|
||||
try
|
||||
{
|
||||
RemoveShortcuts();
|
||||
RemoveUninstallerEntry();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//log and update error message to output above locations where shortcuts may not have been removed
|
||||
#if DEBUG
|
||||
throw;
|
||||
#else
|
||||
throw;// PRODUCTION LOGGING AND CONTINUE
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsPortableModeEnabled()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void RemoveShortcuts()
|
||||
{
|
||||
portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.StartMenu);
|
||||
portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.Desktop);
|
||||
portabilityUpdater.RemoveShortcutsForExecutable(exeName, ShortcutLocation.Startup);
|
||||
}
|
||||
|
||||
public void RemoveUninstallerEntry()
|
||||
{
|
||||
portabilityUpdater.RemoveUninstallerRegistryEntry();
|
||||
}
|
||||
|
||||
public void MoveUserDataFolder(string fromLocation, string toLocation)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -51,6 +51,8 @@
|
|||
<Compile Include="..\SolutionAssemblyInfo.cs">
|
||||
<Link>Properties\SolutionAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Configuration\IPortable.cs" />
|
||||
<Compile Include="Configuration\Portable.cs" />
|
||||
<Compile Include="Plugin\ExecutablePlugin.cs" />
|
||||
<Compile Include="Plugin\PluginsLoader.cs" />
|
||||
<Compile Include="Updater.cs" />
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ namespace Wox.Infrastructure
|
|||
|
||||
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
|
||||
public static readonly string ProgramDirectory = Directory.GetParent(Assembly.Location.NonNull()).ToString();
|
||||
private static readonly string ApplicationDirectory = Directory.GetParent(ProgramDirectory).ToString();
|
||||
public static readonly string RootDirectory = Directory.GetParent(ApplicationDirectory).ToString();
|
||||
public static readonly string ExecutablePath = Path.Combine(ProgramDirectory, Wox + ".exe");
|
||||
public static readonly string DataDirectory = DetermineDataDirectory();
|
||||
public static readonly string PluginsDirectory = Path.Combine(DataDirectory, Plugins);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
|||
using System.Timers;
|
||||
using System.Windows;
|
||||
using Wox.Core;
|
||||
using Wox.Core.Configuration;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Helper;
|
||||
|
|
@ -26,6 +27,7 @@ namespace Wox
|
|||
private MainViewModel _mainVM;
|
||||
private SettingWindowViewModel _settingsVM;
|
||||
private readonly Updater _updater = new Updater(Wox.Properties.Settings.Default.GithubRepo);
|
||||
private readonly Portable _portable = new Portable();
|
||||
private readonly Alphabet _alphabet = new Alphabet();
|
||||
private StringMatcher _stringMatcher;
|
||||
|
||||
|
|
@ -53,7 +55,7 @@ namespace Wox
|
|||
|
||||
ImageLoader.Initialize();
|
||||
|
||||
_settingsVM = new SettingWindowViewModel(_updater);
|
||||
_settingsVM = new SettingWindowViewModel(_updater, _portable);
|
||||
_settings = _settingsVM.Settings;
|
||||
|
||||
_alphabet.Initialize(_settings);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using System.Windows.Controls;
|
|||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Wox.Core;
|
||||
using Wox.Core.Configuration;
|
||||
using Wox.Core.Plugin;
|
||||
using Wox.Core.Resource;
|
||||
using Wox.Helper;
|
||||
|
|
@ -22,11 +23,13 @@ namespace Wox.ViewModel
|
|||
public class SettingWindowViewModel : BaseModel
|
||||
{
|
||||
private readonly Updater _updater;
|
||||
private readonly IPortable _portable;
|
||||
private readonly WoxJsonStorage<Settings> _storage;
|
||||
|
||||
public SettingWindowViewModel(Updater updater)
|
||||
public SettingWindowViewModel(Updater updater, IPortable portable)
|
||||
{
|
||||
_updater = updater;
|
||||
_portable = portable;
|
||||
_storage = new WoxJsonStorage<Settings>();
|
||||
Settings = _storage.Load();
|
||||
Settings.PropertyChanged += (s, e) =>
|
||||
|
|
@ -47,6 +50,11 @@ namespace Wox.ViewModel
|
|||
await _updater.UpdateApp();
|
||||
}
|
||||
|
||||
public void EnablePortableMode()
|
||||
{
|
||||
_portable.EnablePortableMode();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
_storage.Save();
|
||||
|
|
|
|||
Loading…
Reference in a new issue