mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add update from local file
Signed-off-by: Florian Grabmeier <flo.grabmeier@gmail.com>
This commit is contained in:
parent
2e8c91968f
commit
1dd526a2f9
2 changed files with 121 additions and 5 deletions
BIN
Plugins/Flow.Launcher.Plugin.PluginsManager/Images/zipfolder.png
Normal file
BIN
Plugins/Flow.Launcher.Plugin.PluginsManager/Images/zipfolder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
|
|
@ -104,10 +104,18 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
if (MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_update_exists"),
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
Context
|
||||
.API
|
||||
.ChangeQuery(
|
||||
{
|
||||
if (File.Exists(plugin.UrlDownload))
|
||||
{
|
||||
Context.API.ChangeQuery(
|
||||
$"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.UpdateCommand} {plugin.UrlDownload}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.API.ChangeQuery(
|
||||
$"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.UpdateCommand} {plugin.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
var mainWindow = Application.Current.MainWindow;
|
||||
mainWindow.Show();
|
||||
|
|
@ -201,6 +209,110 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
{
|
||||
await PluginsManifest.UpdateManifestAsync(token, usePrimaryUrlOnly);
|
||||
|
||||
if (File.Exists(search) && search.Split('.').Last() == zip)
|
||||
{
|
||||
var plugin = null as UserPlugin;
|
||||
|
||||
using (ZipArchive archive = ZipFile.OpenRead(search))
|
||||
{
|
||||
var pluginJsonPath = archive.Entries.FirstOrDefault(x => x.Name == "plugin.json").ToString();
|
||||
ZipArchiveEntry pluginJsonEntry = archive.GetEntry(pluginJsonPath);
|
||||
|
||||
if (pluginJsonEntry != null)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(pluginJsonEntry.Open()))
|
||||
{
|
||||
string pluginJsonContent = await reader.ReadToEndAsync();
|
||||
plugin = JsonConvert.DeserializeObject<UserPlugin>(pluginJsonContent);
|
||||
plugin.IcoPath = "Images\\zipfolder.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (plugin == null)
|
||||
{
|
||||
return new List<Result>
|
||||
{
|
||||
new Result
|
||||
{
|
||||
Title = Context.API.GetTranslation("plugin_pluginsmanager_update_noresult_title"),
|
||||
SubTitle = Context.API.GetTranslation("plugin_pluginsmanager_update_noresult_subtitle"),
|
||||
IcoPath = icoPath
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var pluginOld = Context.API.GetAllPlugins().FirstOrDefault(x => x.Metadata.ID == plugin.ID);
|
||||
|
||||
return new List<Result> {
|
||||
new Result
|
||||
{
|
||||
|
||||
Title = $"{plugin.Name} by {plugin.Author}",
|
||||
SubTitle = $"Update from version {pluginOld.Metadata.Version} to {plugin.Version}",
|
||||
IcoPath = pluginOld.Metadata.IcoPath,
|
||||
Action = e =>
|
||||
{
|
||||
string message;
|
||||
if (Settings.AutoRestartAfterChanging)
|
||||
{
|
||||
message = string.Format(
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_update_prompt"),
|
||||
plugin.Name, plugin.Author,
|
||||
Environment.NewLine, Environment.NewLine);
|
||||
}
|
||||
else
|
||||
{
|
||||
message = string.Format(
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_update_prompt_no_restart"),
|
||||
plugin.Name, plugin.Author,
|
||||
Environment.NewLine);
|
||||
}
|
||||
|
||||
if (MessageBox.Show(message,
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
|
||||
MessageBoxButton.YesNo) != MessageBoxResult.Yes)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var downloadToFilePath = search;
|
||||
|
||||
|
||||
PluginManager.UpdatePlugin(pluginOld.Metadata, plugin,
|
||||
downloadToFilePath);
|
||||
|
||||
if (Settings.AutoRestartAfterChanging)
|
||||
{
|
||||
Context.API.ShowMsg(
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
|
||||
string.Format(
|
||||
Context.API.GetTranslation(
|
||||
"plugin_pluginsmanager_update_success_restart"),
|
||||
plugin.Name));
|
||||
Context.API.RestartApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.API.ShowMsg(
|
||||
Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
|
||||
string.Format(
|
||||
Context.API.GetTranslation(
|
||||
"plugin_pluginsmanager_update_success_no_restart"),
|
||||
plugin.Name));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
ContextData =
|
||||
new UserPlugin
|
||||
{
|
||||
Website = plugin.Website,
|
||||
UrlSourceCode = plugin.UrlSourceCode
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
var resultsForUpdate = (
|
||||
from existingPlugin in Context.API.GetAllPlugins()
|
||||
join pluginFromManifest in PluginsManifest.UserPlugins
|
||||
|
|
@ -498,7 +610,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
{
|
||||
string pluginJsonContent = reader.ReadToEnd();
|
||||
plugin = JsonConvert.DeserializeObject<UserPlugin>(pluginJsonContent);
|
||||
plugin.IcoPath = Path.Combine(path, pluginJsonEntry.FullName.Split('/')[0], plugin.IcoPath);
|
||||
plugin.IcoPath = "Images\\zipfolder.png";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -584,7 +696,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
|
|||
try
|
||||
{
|
||||
PluginManager.InstallPlugin(plugin, downloadedFilePath);
|
||||
File.Delete(downloadedFilePath);
|
||||
if (downloadedFilePath.StartsWith(Path.GetTempPath()))
|
||||
{
|
||||
File.Delete(downloadedFilePath);
|
||||
}
|
||||
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue