Ejemplo n.º 1
0
        private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
        {
            string         configPath = Path.Combine(pluginDirectory, Constant.PluginMetadataFileName);
            PluginMetadata metadata;

            if (!File.Exists(configPath))
            {
                return(null);
            }

            try
            {
                metadata = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;
            }
            catch (Exception e)
            {
                Log.Exception($"|PluginInstaller.GetMetadataFromJson|plugin config {configPath} failed: invalid json format", e);
                return(null);
            }

            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                Log.Error($"|PluginInstaller.GetMetadataFromJson|plugin config {configPath} failed: invalid language {metadata.Language}");
                return(null);
            }
            if (!File.Exists(metadata.ExecuteFilePath))
            {
                Log.Error($"|PluginInstaller.GetMetadataFromJson|plugin config {configPath} failed: file {metadata.ExecuteFilePath} doesn't exist");
                return(null);
            }

            return(metadata);
        }
Ejemplo n.º 2
0
        private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
        {
            string         configPath = Path.Combine(pluginDirectory, PluginConfigName);
            PluginMetadata metadata;

            if (!File.Exists(configPath))
            {
                Log.Warn(string.Format("parse plugin {0} failed: didn't find config file.", configPath));
                return(null);
            }

            try {
                metadata                 = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginType      = PluginType.ThirdParty;
                metadata.PluginDirectory = pluginDirectory;
            }
            catch (Exception) {
                string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
                Log.Warn(error);
#if (DEBUG)
                {
                    throw new WoxException(error);
                }
#endif
                return(null);
            }


            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath, metadata.Language);
                Log.Warn(error);
#if (DEBUG)
                {
                    throw new WoxException(error);
                }
#endif
                return(null);
            }
            if (!File.Exists(metadata.ExecuteFilePath))
            {
                string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath, metadata.ExecuteFilePath);
                Log.Warn(error);
#if (DEBUG)
                {
                    throw new WoxException(error);
                }
#endif
                return(null);
            }

            var customizedPluginConfig =
                UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);
            if (customizedPluginConfig != null && !string.IsNullOrEmpty(customizedPluginConfig.Actionword))
            {
                metadata.ActionKeyword = customizedPluginConfig.Actionword;
            }

            return(metadata);
        }
Ejemplo n.º 3
0
        private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
        {
            string         configPath = Path.Combine(pluginDirectory, PluginConfigName);
            PluginMetadata metadata;

            if (!File.Exists(configPath))
            {
                Log.Error(string.Format("parse plugin {0} failed: didn't find config file.", configPath));
                return(null);
            }

            try
            {
                metadata                 = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginType      = PluginType.ThirdParty;
                metadata.PluginDirecotry = pluginDirectory;
            }
            catch (Exception)
            {
                string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
                Log.Error(error);
#if (DEBUG)
                {
                    throw new WoxException(error);
                }
#endif
                return(null);
            }


            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath,
                                             metadata.Language);
                Log.Error(error);
#if (DEBUG)
                {
                    throw new WoxException(error);
                }
#endif
                return(null);
            }
            if (!File.Exists(metadata.ExecuteFilePath))
            {
                string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath,
                                             metadata.ExecuteFilePath);
                Log.Error(error);
#if (DEBUG)
                {
                    throw new WoxException(error);
                }
#endif
                return(null);
            }

            return(metadata);
        }
Ejemplo n.º 4
0
        private static PluginMetadata GetPluginMetadata(string pluginDirectory)
        {
            string configPath = Path.Combine(pluginDirectory, pluginConfigName);

            if (!File.Exists(configPath))
            {
                Log.Warn($"parse plugin {configPath} failed: didn't find config file.");
                return(null);
            }

            PluginMetadata metadata;

            try
            {
                metadata = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;
                // for plugins which doesn't has ActionKeywords key
                metadata.ActionKeywords = metadata.ActionKeywords ?? new List <string> {
                    metadata.ActionKeyword
                };
                // for plugin still use old ActionKeyword
                metadata.ActionKeyword = metadata.ActionKeywords?[0];
            }
            catch (System.Exception e)
            {
                string msg = $"Parse plugin config {configPath} failed: json format is not valid";
                Log.Error(new WoxException(msg));
                return(null);
            }


            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                string msg = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
                Log.Error(new WoxException(msg));
                return(null);
            }

            if (!File.Exists(metadata.ExecuteFilePath))
            {
                string msg = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
                Log.Error(new WoxException(msg));
                return(null);
            }

            //replace action keyword if user customized it.
            var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == metadata.ID);

            if (customizedPluginConfig?.ActionKeywords?.Count > 0)
            {
                metadata.ActionKeywords = customizedPluginConfig.ActionKeywords;
                metadata.ActionKeyword  = customizedPluginConfig.ActionKeywords[0];
            }

            return(metadata);
        }
Ejemplo n.º 5
0
        private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
        {
            string         configPath = Path.Combine(pluginDirectory, "plugin.json");
            PluginMetadata metadata;

            if (!File.Exists(configPath))
            {
                return(null);
            }

            try
            {
                metadata = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;
            }
            catch (Exception e)
            {
                string error = $"Parse plugin config {configPath} failed: json format is not valid";
                Log.Exception(error, e, MethodBase.GetCurrentMethod().DeclaringType);
#if DEBUG
                {
                    throw new Exception(error);
                }
#else
                return(null);
#endif
            }

            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
#if DEBUG
                {
                    throw new Exception(error);
                }
#else
                return(null);
#endif
            }

            if (!File.Exists(metadata.ExecuteFilePath))
            {
                string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
#if DEBUG
                {
                    throw new Exception(error);
                }
#else
                return(null);
#endif
            }

            return(metadata);
        }
Ejemplo n.º 6
0
        private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
        {
            var            configPath = Path.Combine(pluginDirectory, PluginConfig.PluginConfigName);
            PluginMetadata metadata;

            if (!File.Exists(configPath))
            {
                return(null);
            }

            try
            {
                metadata = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;
            }
            catch (Exception)
            {
                var error = $"Parse plugin config {configPath} failed: json format is not valid";
#if (DEBUG)
                {
                    throw new Exception(error);
                }
#endif
                return(null);
            }


            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                var error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
#if (DEBUG)
                {
                    throw new Exception(error);
                }
#endif
                return(null);
            }

            if (!File.Exists(metadata.ExecuteFilePath))
            {
                var error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
#if (DEBUG)
                {
                    throw new Exception(error);
                }
#endif
                return(null);
            }

            return(metadata);
        }
Ejemplo n.º 7
0
        private static PluginMetadata GetPluginMetadata(string pluginDirectory)
        {
            string configPath = Path.Combine(pluginDirectory, pluginConfigName);

            if (!File.Exists(configPath))
            {
                Log.Warn($"parse plugin {configPath} failed: didn't find config file.");
                return(null);
            }

            PluginMetadata metadata;

            try
            {
                metadata = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;
                // for plugins which doesn't has ActionKeywords key
                metadata.ActionKeywords = metadata.ActionKeywords ?? new List <string> {
                    metadata.ActionKeyword
                };
                // for plugin still use old ActionKeyword
                metadata.ActionKeyword = metadata.ActionKeywords?[0];
            }
            catch (Exception e)
            {
                string msg = $"Parse plugin config {configPath} failed: json format is not valid";
                Log.Error(new WoxException(msg));
                return(null);
            }


            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                string msg = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
                Log.Error(new WoxException(msg));
                return(null);
            }

            if (!File.Exists(metadata.ExecuteFilePath))
            {
                string msg = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
                Log.Error(new WoxException(msg));
                return(null);
            }

            return(metadata);
        }
Ejemplo n.º 8
0
        private static PluginMetadata GetPluginMetadata(string pluginDirectory)
        {
            string configPath = Path.Combine(pluginDirectory, PluginConfigName);

            if (!File.Exists(configPath))
            {
                Log.Error($"Didn't find config file <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType);

                return(null);
            }

            PluginMetadata metadata;

            try
            {
                metadata = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;

                // for plugins which doesn't has ActionKeywords key
                metadata.ActionKeywords = metadata.ActionKeywords ?? new List <string> {
                    metadata.ActionKeyword
                };

                // for plugin still use old ActionKeyword
                metadata.ActionKeyword = metadata.ActionKeywords?[0];
            }
            catch (Exception e)
            {
                Log.Exception($"|PluginConfig.GetPluginMetadata|invalid json for config <{configPath}>", e, MethodBase.GetCurrentMethod().DeclaringType);
                return(null);
            }

            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                Log.Error($"|PluginConfig.GetPluginMetadata|Invalid language <{metadata.Language}> for config <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType);
                return(null);
            }

            if (!File.Exists(metadata.ExecuteFilePath))
            {
                Log.Error($"|PluginConfig.GetPluginMetadata|execute file path didn't exist <{metadata.ExecuteFilePath}> for config <{configPath}", MethodBase.GetCurrentMethod().DeclaringType);
                return(null);
            }

            return(metadata);
        }
Ejemplo n.º 9
0
        private static PluginMetadata GetPluginMetadata(string pluginDirectory)
        {
            string configPath = Path.Combine(pluginDirectory, PluginConfigName);

            if (!File.Exists(configPath))
            {
                Logger.WoxError($"Didn't find config file <{configPath}>");
                return(null);
            }

            PluginMetadata metadata;

            try
            {
                metadata = JsonConvert.DeserializeObject <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;
                // for plugins which doesn't has ActionKeywords key
                metadata.ActionKeywords = metadata.ActionKeywords ?? new List <string> {
                    metadata.ActionKeyword
                };
                // for plugin still use old ActionKeyword
                metadata.ActionKeyword = metadata.ActionKeywords?[0];
            }
            catch (Exception e)
            {
                e.Data.Add(nameof(configPath), configPath);
                e.Data.Add(nameof(pluginDirectory), pluginDirectory);
                Logger.WoxError($"invalid json for config <{configPath}>", e);
                return(null);
            }


            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                Logger.WoxError($"Invalid language <{metadata.Language}> for config <{configPath}>");
                return(null);
            }

            if (!File.Exists(metadata.ExecuteFilePath))
            {
                Logger.WoxError($"execute file path didn't exist <{metadata.ExecuteFilePath}> for conifg <{configPath}");
                return(null);
            }

            return(metadata);
        }
Ejemplo n.º 10
0
        private static PluginMetadata GetPluginMetadata(string pluginDirectory)
        {
            string configPath = Path.Combine(pluginDirectory, PluginConfigName);

            if (!File.Exists(configPath))
            {
                Log.Error($"Didn't find config file <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType);

                return(null);
            }

            PluginMetadata metadata;

            try
            {
                metadata = JsonSerializer.Deserialize <PluginMetadata>(File.ReadAllText(configPath));
                metadata.PluginDirectory = pluginDirectory;
            }
            catch (Exception e)
            {
                Log.Exception($"|PluginConfig.GetPluginMetadata|invalid json for config <{configPath}>", e, MethodBase.GetCurrentMethod().DeclaringType);
                return(null);
            }

            if (!AllowedLanguage.IsAllowed(metadata.Language))
            {
                Log.Error($"|PluginConfig.GetPluginMetadata|Invalid language <{metadata.Language}> for config <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType);
                return(null);
            }

            if (string.IsNullOrEmpty(metadata.IcoPathDark) || string.IsNullOrEmpty(metadata.IcoPathLight))
            {
                Log.Error($"|PluginConfig.GetPluginMetadata|couldn't get icon information for config <{configPath}>", MethodBase.GetCurrentMethod().DeclaringType);
                return(null);
            }

            if (!File.Exists(metadata.ExecuteFilePath))
            {
                Log.Error($"|PluginConfig.GetPluginMetadata|execute file path didn't exist <{metadata.ExecuteFilePath}> for config <{configPath}", MethodBase.GetCurrentMethod().DeclaringType);
                return(null);
            }

            return(metadata);
        }