internal async Task InstallOrUpdate(UserPlugin plugin)
        {
            if (PluginExists(plugin.ID))
            {
                if (Context.API.GetAllPlugins()
                    .Any(x => x.Metadata.ID == plugin.ID && x.Metadata.Version.CompareTo(plugin.Version) < 0))
                {
                    if (MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_update_exists"),
                                        Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
                                        MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        Context
                        .API
                        .ChangeQuery(
                            $"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.HotkeyUpdate} {plugin.Name}");
                    }

                    Application.Current.MainWindow.Show();
                    shouldHideWindow = false;

                    return;
                }

                Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_alreadyexists"));
                return;
            }

            var message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_prompt"),
                                        plugin.Name, plugin.Author,
                                        Environment.NewLine, Environment.NewLine);

            if (MessageBox.Show(message, Context.API.GetTranslation("plugin_pluginsmanager_install_title"),
                                MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                return;
            }

            var filePath = Path.Combine(DataLocation.PluginsDirectory, $"{plugin.Name}-{plugin.Version}.zip");

            try
            {
                Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
                                    Context.API.GetTranslation("plugin_pluginsmanager_please_wait"));

                await Http.Download(plugin.UrlDownload, filePath).ConfigureAwait(false);

                Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
                                    Context.API.GetTranslation("plugin_pluginsmanager_download_success"));
            }
            catch (Exception e)
            {
                Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
                                    Context.API.GetTranslation("plugin_pluginsmanager_download_success"));

                Log.Exception("PluginsManager", "An error occured while downloading plugin", e, "PluginDownload");
            }

            Install(plugin, filePath);
            Context.API.RestartApp();
        }
 public ActionResult Login(UserPlugin model, string ReturnUrl)
 {
     if (Membership.ValidateUser(model.Account, model.Password))
     {
         FormsAuthentication.SetAuthCookie(model.Account, false);
         if (!string.IsNullOrEmpty(ReturnUrl))
         {
             return(Redirect(ReturnUrl));
         }
         return(RedirectToAction("Admin", "Home"));
     }
     return(View(model));
 }
Exemple #3
0
        internal List <Result> InstallFromWeb(string url)
        {
            var filename = url.Split("/").Last();
            var name     = filename.Split(string.Format(".{0}", zip)).First();

            var plugin = new UserPlugin
            {
                ID          = "",
                Name        = name,
                Version     = string.Empty,
                Author      = Context.API.GetTranslation("plugin_pluginsmanager_unknown_author"),
                UrlDownload = url
            };

            var result = new Result
            {
                Title    = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_from_web"), filename),
                SubTitle = plugin.UrlDownload,
                IcoPath  = icoPath,
                Action   = e =>
                {
                    if (e.SpecialKeyState.CtrlPressed)
                    {
                        SearchWeb.OpenInBrowserTab(plugin.UrlDownload);
                        return(ShouldHideWindow);
                    }

                    if (Settings.WarnFromUnknownSource)
                    {
                        if (!InstallSourceKnown(plugin.UrlDownload) &&
                            MessageBox.Show(string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning"),
                                                          Environment.NewLine),
                                            Context.API.GetTranslation("plugin_pluginsmanager_install_unknown_source_warning_title"),
                                            MessageBoxButton.YesNo) == MessageBoxResult.No)
                        {
                            return(false);
                        }
                    }

                    Application.Current.MainWindow.Hide();
                    _ = InstallOrUpdate(plugin);

                    return(ShouldHideWindow);
                }
            };

            return(new List <Result>
            {
                result
            });
        }
Exemple #4
0
        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 ActionResult AddPlugin()
        {
            try
            {
                UserPlugin userPluginModel = new UserPlugin();
                TryUpdateModel(userPluginModel);
                userPluginModel.SubscriptionTime = DateTime.Now;

                using (var db = new Database(Environments.Current.Connection, "System.Data.SqlClient"))
                {
                    db.Execute(@"insert into UserPlugin (UserID, PluginID, TypeID, SubscriptionTime) values (@0, @1, @2, @3)", userPluginModel.UserID, userPluginModel.PluginID, userPluginModel.TypeID, DateTime.Now);
                }
                return(Success("Registration complete"));
            }
            catch (Exception)
            {
                return(Failure("Something went wrong while registering to a plugin"));
            }
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        internal async Task InstallOrUpdate(UserPlugin plugin)
        {
            if (PluginExists(plugin.ID))
            {
                if (Context.API.GetAllPlugins()
                    .Any(x => x.Metadata.ID == plugin.ID && x.Metadata.Version.CompareTo(plugin.Version) < 0))
                {
                    if (MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_update_exists"),
                                        Context.API.GetTranslation("plugin_pluginsmanager_update_title"),
                                        MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                    {
                        Context
                        .API
                        .ChangeQuery(
                            $"{Context.CurrentPluginMetadata.ActionKeywords.FirstOrDefault()} {Settings.HotkeyUpdate} {plugin.Name}");
                    }

                    var mainWindow = Application.Current.MainWindow;
                    mainWindow.Show();
                    mainWindow.Focus();

                    shouldHideWindow = false;

                    return;
                }

                Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_update_alreadyexists"));
                return;
            }

            var message = string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_prompt"),
                                        plugin.Name, plugin.Author,
                                        Environment.NewLine, Environment.NewLine);

            if (MessageBox.Show(message, Context.API.GetTranslation("plugin_pluginsmanager_install_title"),
                                MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                return;
            }

            // at minimum should provide a name, but handle plugin that is not downloaded from plugins manifest and is a url download
            var downloadFilename = string.IsNullOrEmpty(plugin.Version)
                ? $"{plugin.Name}-{Guid.NewGuid()}.zip"
                : $"{plugin.Name}-{plugin.Version}.zip";

            var filePath = Path.Combine(DataLocation.PluginsDirectory, downloadFilename);

            try
            {
                await Http.DownloadAsync(plugin.UrlDownload, filePath).ConfigureAwait(false);

                Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"),
                                    Context.API.GetTranslation("plugin_pluginsmanager_download_success"));

                Install(plugin, filePath);
            }
            catch (Exception e)
            {
                if (e is HttpRequestException)
                {
                    MessageBox.Show(Context.API.GetTranslation("plugin_pluginsmanager_download_error"),
                                    Context.API.GetTranslation("plugin_pluginsmanager_downloading_plugin"));
                }

                Context.API.ShowMsgError(Context.API.GetTranslation("plugin_pluginsmanager_install_error_title"),
                                         string.Format(Context.API.GetTranslation("plugin_pluginsmanager_install_error_subtitle"),
                                                       plugin.Name));

                Log.Exception("PluginsManager", "An error occured while downloading plugin", e, "InstallOrUpdate");

                return;
            }

            Context.API.ShowMsg(Context.API.GetTranslation("plugin_pluginsmanager_install_title"),
                                Context.API.GetTranslation("plugin_pluginsmanager_install_success_restart"));

            Context.API.RestartApp();
        }