From 1dd526a2f984e1876f912a4d6a27f3f753f7a33e Mon Sep 17 00:00:00 2001 From: Florian Grabmeier Date: Sun, 4 Feb 2024 17:29:05 +0100 Subject: [PATCH] Add update from local file Signed-off-by: Florian Grabmeier --- .../Images/zipfolder.png | Bin 0 -> 2939 bytes .../PluginsManager.cs | 126 +++++++++++++++++- 2 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 Plugins/Flow.Launcher.Plugin.PluginsManager/Images/zipfolder.png diff --git a/Plugins/Flow.Launcher.Plugin.PluginsManager/Images/zipfolder.png b/Plugins/Flow.Launcher.Plugin.PluginsManager/Images/zipfolder.png new file mode 100644 index 0000000000000000000000000000000000000000..5d3ed0ace3f8a26662b82611eccd95463f32f8c8 GIT binary patch literal 2939 zcmV->3xxEEP)i4qW7iveum z16oBzMNC8s@qNxuAq%F7b`~q@dk$jEvAH z1Q7W&9nVLj$jZPtuZ4~|T^x@3<`BCuQ~-sZYRY-Wmbr)^svJkF5U~?r91*aia=Wq4 zoxmb-Kpf)HOg|}ysYLFfhvI`65Th4{zPWJh4cTOUc|+2=gQ()fw(?9tRKEx=^__suGCbd{taS^cvz?pSRFQ0GsGTxDv_At|*8lUBqf*)B-Ih`BNl`@5os zK!OA~Dv;=x5?n2*v9qBiK-0)L_N(x5`v4ILeXL)NQgq|)?O0~K3=Bvrg*aZ_PD%tS zRmXvb1rRVo_(2gAoX!HqYm35^L_6i_KtL7sM+t_8!1_2{`C1P7qsu1B2sbK#QG)%W zc*ifK<15#bp1%r7chIW-<0x7!;_rQtp$%73-u5DHZx(F*@~JO?2*JQ8-U&TU&wY$9%JRe zJ^)YLOKZ^8C_=$F6jtWO{{@Be2n_F1%EL7gm?VH#fWGB|-aAhoWx8W#D{Q-$0!0h=w2-B z*%BR^h=SZUqMF~T53UrxE}EKKMhA>S@o*TWlrp8UIi zfUsJNr(?*}Ff_JQ%lNa;X5ce7APQ2)3#mYH-ual|eX=|M0@-*!V!W*bun?wt5FgxX zxq*H_Q7I5+l99i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cF~g`Vc%$hRZDhq_NgzC3Ioo%-qZd(~I+)i(ypV#*t&(hvkxoGVs_y8DkVJtZ_VhM?Y0D+-Wo@(Hdas!M+ zBVa+XYNAA309YpxHGiCBv;Y+-dHnp$hsb*sMr@vKJ1noflcgZ$>6A~|PqAtHG6)Qq1nkZrDK2O-YN9tz)!a)pbm>l) z>FGK^cm4oZo%H~uEL74>Hnc7u=L;O-OaD+8Yd`lAzxwV*+_He@!$=|i{@)dW$x%?1 z#3ZmLV^v6*05=~*g+7{(ci{`s>b(KG2__5B7yglQ{MXS;#fTDECt9oPd(AedJ{1FP z_AX8ty9*`@u( 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(pluginJsonContent); + plugin.IcoPath = "Images\\zipfolder.png"; + } + } + } + if (plugin == null) + { + return new List + { + 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 { + 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(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) {