private void Install(UserPlugin plugin, string downloadedFilePath) { if (!File.Exists(downloadedFilePath)) { return; } var tempFolderPath = Path.Combine(Path.GetTempPath(), "flowlauncher"); var tempFolderPluginPath = Path.Combine(tempFolderPath, "plugin"); if (Directory.Exists(tempFolderPath)) { Directory.Delete(tempFolderPath, true); } Directory.CreateDirectory(tempFolderPath); var zipFilePath = Path.Combine(tempFolderPath, Path.GetFileName(downloadedFilePath)); File.Copy(downloadedFilePath, zipFilePath); File.Delete(downloadedFilePath); Utilities.UnZip(zipFilePath, tempFolderPluginPath, true); var pluginFolderPath = Utilities.GetContainingFolderPathAfterUnzip(tempFolderPluginPath); var metadataJsonFilePath = string.Empty; if (File.Exists(Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName))) { metadataJsonFilePath = Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName); } if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath)) { MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile")); return; } string newPluginPath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}-{plugin.Version}"); FilesFolders.CopyAll(pluginFolderPath, newPluginPath); Directory.Delete(pluginFolderPath, true); }
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true) { try { UpdateInfo newUpdateInfo; if (!silentUpdate) { api.ShowMsg(api.GetTranslation("pleaseWait"), api.GetTranslation("update_flowlauncher_update_check")); } using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false); // UpdateApp CheckForUpdate will return value only if the app is squirrel installed newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false); var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString()); var currentVersion = Version.Parse(Constant.Version); Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>"); if (newReleaseVersion <= currentVersion) { if (!silentUpdate) { MessageBox.Show(api.GetTranslation("update_flowlauncher_already_on_latest")); } return; } if (!silentUpdate) { api.ShowMsg(api.GetTranslation("update_flowlauncher_update_found"), api.GetTranslation("update_flowlauncher_updating")); } await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false); await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false); if (DataLocation.PortableDataLocationInUse()) { var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}"; FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination); if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination)) { MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"), DataLocation.PortableDataPath, targetDestination)); } } else { await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false); } var newVersionTips = NewVersinoTips(newReleaseVersion.ToString()); Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}"); if (MessageBox.Show(newVersionTips, api.GetTranslation("update_flowlauncher_new_update"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) { UpdateManager.RestartApp(Constant.ApplicationFileName); } } catch (Exception e) when(e is HttpRequestException || e is WebException || e is SocketException || e is TaskCanceledException) { Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e); api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"), api.GetTranslation("update_flowlauncher_check_connection")); return; } }
public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true) { try { UpdateInfo newUpdateInfo; if (!silentUpdate) { api.ShowMsg("Please wait...", "Checking for new update"); } using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false); // UpdateApp CheckForUpdate will return value only if the app is squirrel installed newUpdateInfo = await updateManager.CheckForUpdate().NonNull().ConfigureAwait(false); var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString()); var currentVersion = Version.Parse(Constant.Version); Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>"); if (newReleaseVersion <= currentVersion) { if (!silentUpdate) { MessageBox.Show("You already have the latest Flow Launcher version"); } return; } if (!silentUpdate) { api.ShowMsg("Update found", "Updating..."); } await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false); await updateManager.ApplyReleases(newUpdateInfo).ConfigureAwait(false); if (DataLocation.PortableDataLocationInUse()) { var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}"; FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination); if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination)) { MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " + $"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}"); } } else { await updateManager.CreateUninstallerRegistryEntry().ConfigureAwait(false); } var newVersionTips = NewVersinoTips(newReleaseVersion.ToString()); Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}"); if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { UpdateManager.RestartApp(Constant.ApplicationFileName); } } catch (Exception e) when(e is HttpRequestException || e is WebException || e is SocketException) { Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e); api.ShowMsg("Update Failed", "Check your connection and try updating proxy settings to github-cloud.s3.amazonaws.com."); return; } }
public void MoveUserDataFolder(string fromLocation, string toLocation) { FilesFolders.CopyAll(fromLocation, toLocation); VerifyUserDataAfterMove(fromLocation, toLocation); }
private void Install(UserPlugin plugin, string downloadedFilePath) { if (!File.Exists(downloadedFilePath)) { return; } var tempFolderPath = Path.Combine(Path.GetTempPath(), "flowlauncher"); var tempFolderPluginPath = Path.Combine(tempFolderPath, "plugin"); if (Directory.Exists(tempFolderPath)) { Directory.Delete(tempFolderPath, true); } Directory.CreateDirectory(tempFolderPath); var zipFilePath = Path.Combine(tempFolderPath, Path.GetFileName(downloadedFilePath)); File.Copy(downloadedFilePath, zipFilePath); File.Delete(downloadedFilePath); Utilities.UnZip(zipFilePath, tempFolderPluginPath, true); var pluginFolderPath = Utilities.GetContainingFolderPathAfterUnzip(tempFolderPluginPath); var metadataJsonFilePath = string.Empty; if (File.Exists(Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName))) { metadataJsonFilePath = Path.Combine(pluginFolderPath, Constant.PluginMetadataFileName); } if (string.IsNullOrEmpty(metadataJsonFilePath) || string.IsNullOrEmpty(pluginFolderPath)) { MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_install_errormetadatafile"), Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); throw new FileNotFoundException( string.Format("Unable to find plugin.json from the extracted zip file, or this path {0} does not exist", pluginFolderPath)); } if (SameOrLesserPluginVersionExists(metadataJsonFilePath)) { MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_duplicate"), plugin.Name), Context.API.GetTranslation("plugin_pluginsmanager_install_error_title")); throw new InvalidOperationException( string.Format("A plugin with the same ID and version already exists, " + "or the version is greater than this downloaded plugin {0}", plugin.Name)); } var directory = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}"; var newPluginPath = Path.Combine(DataLocation.PluginsDirectory, directory); FilesFolders.CopyAll(pluginFolderPath, newPluginPath); Directory.Delete(pluginFolderPath, true); }