Пример #1
0
        /// <summary>
        /// Mark plugin as installed
        /// </summary>
        /// <param name="systemName">Plugin system name</param>
        public static void MarkPluginAsInstalled(string systemName)
        {
            if (string.IsNullOrEmpty(systemName))
            {
                throw new ArgumentNullException(nameof(systemName));
            }

            var filePath = _fileProvider.MapPath(NopPluginDefaults.InstalledPluginsFilePath);

            //create file if not exists
            _fileProvider.CreateFile(filePath);

            //get installed plugin names
            var installedPluginSystemNames = GetInstalledPluginNames(filePath);

            //add plugin system name to the list if doesn't already exist
            var alreadyMarkedAsInstalled = installedPluginSystemNames.Any(pluginName => pluginName.Equals(systemName, StringComparison.InvariantCultureIgnoreCase));

            if (!alreadyMarkedAsInstalled)
            {
                installedPluginSystemNames.Add(systemName);
            }

            //save installed plugin names to the file
            SaveInstalledPluginNames(installedPluginSystemNames, filePath);
        }
Пример #2
0
        /// <summary>
        /// Create app settings with the passed configurations and save it to the file
        /// </summary>
        /// <param name="configurations">Configurations to save</param>
        /// <param name="fileProvider">File provider</param>
        /// <param name="overwrite">Whether to overwrite appsettings file</param>
        /// <returns>App settings</returns>
        public static AppSettings SaveAppSettings(IList <IConfig> configurations, INopFileProvider fileProvider, bool overwrite = true)
        {
            if (configurations is null)
            {
                throw new ArgumentNullException(nameof(configurations));
            }

            if (_configurationOrder is null)
            {
                _configurationOrder = configurations.ToDictionary(config => config.Name, config => config.GetOrder());
            }

            //create app settings
            var appSettings = Singleton <AppSettings> .Instance ?? new AppSettings();

            appSettings.Update(configurations);
            Singleton <AppSettings> .Instance = appSettings;

            //create file if not exists
            var filePath   = fileProvider.MapPath(NopConfigurationDefaults.AppSettingsFilePath);
            var fileExists = fileProvider.FileExists(filePath);

            fileProvider.CreateFile(filePath);

            //get raw configuration parameters
            var configuration = JsonConvert.DeserializeObject <AppSettings>(fileProvider.ReadAllText(filePath, Encoding.UTF8))
                                ?.Configuration
                                ?? new();

            foreach (var config in configurations)
            {
                configuration[config.Name] = JToken.FromObject(config);
            }

            //sort configurations for display by order (e.g. data configuration with 0 will be the first)
            appSettings.Configuration = configuration
                                        .SelectMany(outConfig => _configurationOrder.Where(inConfig => inConfig.Key == outConfig.Key).DefaultIfEmpty(),
                                                    (outConfig, inConfig) => new { OutConfig = outConfig, InConfig = inConfig })
                                        .OrderBy(config => config.InConfig.Value)
                                        .Select(config => config.OutConfig)
                                        .ToDictionary(config => config.Key, config => config.Value);

            //save app settings to the file
            if (!fileExists || overwrite)
            {
                var text = JsonConvert.SerializeObject(appSettings, Formatting.Indented);
                fileProvider.WriteAllText(filePath, text, Encoding.UTF8);
            }

            return(appSettings);
        }
Пример #3
0
        /// <summary>
        /// Save settings to a file
        /// </summary>
        /// <param name="settings">Data settings</param>
        public virtual void SaveSettings(DataSettings settings)
        {
            Singleton <DataSettings> .Instance = settings ?? throw new ArgumentNullException(nameof(settings));

            var filePath = _fileProvider.MapPath(DataSettingsFilePath);

            //create file if not exists
            _fileProvider.CreateFile(filePath);

            //save data settings to the file
            var text = JsonConvert.SerializeObject(Singleton <DataSettings> .Instance, Formatting.Indented);

            _fileProvider.WriteAllText(filePath, text, Encoding.UTF8);
        }
Пример #4
0
        /// <summary>
        /// Save data settings to the file
        /// </summary>
        /// <param name="settings">Data settings</param>
        /// <param name="fileProvider">File provider</param>
        public static void SaveSettings(DataSettings settings, INopFileProvider fileProvider = null)
        {
            Singleton <DataSettings> .Instance = settings ?? throw new ArgumentNullException(nameof(settings));

            fileProvider = fileProvider ?? CommonHelper.DefaultFileProvider;
            var filePath = fileProvider.MapPath(NopDataSettingsDefaults.FilePath);

            //create file if not exists
            fileProvider.CreateFile(filePath);

            //save data settings to the file
            var text = JsonConvert.SerializeObject(Singleton <DataSettings> .Instance, Formatting.Indented);

            fileProvider.WriteAllText(filePath, text, Encoding.UTF8);
        }
Пример #5
0
        /// <summary>
        /// Save app settings to the file
        /// </summary>
        /// <param name="appSettings">App settings</param>
        /// <param name="fileProvider">File provider</param>
        public static async Task SaveAppSettingsAsync(AppSettings appSettings, INopFileProvider fileProvider = null)
        {
            Singleton <AppSettings> .Instance = appSettings ?? throw new ArgumentNullException(nameof(appSettings));

            fileProvider ??= CommonHelper.DefaultFileProvider;

            //create file if not exists
            var filePath = fileProvider.MapPath(NopConfigurationDefaults.AppSettingsFilePath);

            fileProvider.CreateFile(filePath);

            //check additional configuration parameters
            var additionalData = JsonConvert.DeserializeObject <AppSettings>(await fileProvider.ReadAllTextAsync(filePath, Encoding.UTF8))?.AdditionalData;

            appSettings.AdditionalData = additionalData;

            //save app settings to the file
            var text = JsonConvert.SerializeObject(appSettings, Formatting.Indented);
            await fileProvider.WriteAllTextAsync(filePath, text, Encoding.UTF8);
        }
        /// <summary>
        /// Create configuration file for RoxyFileman
        /// </summary>
        public virtual void CreateConfiguration()
        {
            var filePath = GetConfigurationFilePath();

            //create file if not exists
            _fileProvider.CreateFile(filePath);

            //try to read existing configuration
            var existingText          = _fileProvider.ReadAllText(filePath, Encoding.UTF8);
            var existingConfiguration = JsonConvert.DeserializeAnonymousType(existingText, new
            {
                FILES_ROOT           = string.Empty,
                SESSION_PATH_KEY     = string.Empty,
                THUMBS_VIEW_WIDTH    = string.Empty,
                THUMBS_VIEW_HEIGHT   = string.Empty,
                PREVIEW_THUMB_WIDTH  = string.Empty,
                PREVIEW_THUMB_HEIGHT = string.Empty,
                MAX_IMAGE_WIDTH      = string.Empty,
                MAX_IMAGE_HEIGHT     = string.Empty,
                DEFAULTVIEW          = string.Empty,
                FORBIDDEN_UPLOADS    = string.Empty,
                ALLOWED_UPLOADS      = string.Empty,
                FILEPERMISSIONS      = string.Empty,
                DIRPERMISSIONS       = string.Empty,
                LANG              = string.Empty,
                DATEFORMAT        = string.Empty,
                OPEN_LAST_DIR     = string.Empty,
                INTEGRATION       = string.Empty,
                RETURN_URL_PREFIX = string.Empty,
                DIRLIST           = string.Empty,
                CREATEDIR         = string.Empty,
                DELETEDIR         = string.Empty,
                MOVEDIR           = string.Empty,
                COPYDIR           = string.Empty,
                RENAMEDIR         = string.Empty,
                FILESLIST         = string.Empty,
                UPLOAD            = string.Empty,
                DOWNLOAD          = string.Empty,
                DOWNLOADDIR       = string.Empty,
                DELETEFILE        = string.Empty,
                MOVEFILE          = string.Empty,
                COPYFILE          = string.Empty,
                RENAMEFILE        = string.Empty,
                GENERATETHUMB     = string.Empty
            });

            //check whether the path base has changed, otherwise there is no need to overwrite the configuration file
            var currentPathBase = _httpContextAccessor.HttpContext.Request.PathBase.ToString();

            if (existingConfiguration?.RETURN_URL_PREFIX?.Equals(currentPathBase) ?? false)
            {
                return;
            }

            //create configuration
            var configuration = new
            {
                FILES_ROOT           = existingConfiguration?.FILES_ROOT ?? NopRoxyFilemanDefaults.DefaultRootDirectory,
                SESSION_PATH_KEY     = existingConfiguration?.SESSION_PATH_KEY ?? string.Empty,
                THUMBS_VIEW_WIDTH    = existingConfiguration?.THUMBS_VIEW_WIDTH ?? "140",
                THUMBS_VIEW_HEIGHT   = existingConfiguration?.THUMBS_VIEW_HEIGHT ?? "120",
                PREVIEW_THUMB_WIDTH  = existingConfiguration?.PREVIEW_THUMB_WIDTH ?? "300",
                PREVIEW_THUMB_HEIGHT = existingConfiguration?.PREVIEW_THUMB_HEIGHT ?? "200",
                MAX_IMAGE_WIDTH      = existingConfiguration?.MAX_IMAGE_WIDTH ?? "1000",
                MAX_IMAGE_HEIGHT     = existingConfiguration?.MAX_IMAGE_HEIGHT ?? "1000",
                DEFAULTVIEW          = existingConfiguration?.DEFAULTVIEW ?? "list",
                FORBIDDEN_UPLOADS    = existingConfiguration?.FORBIDDEN_UPLOADS ?? "zip js jsp jsb mhtml mht xhtml xht php phtml " +
                                       "php3 php4 php5 phps shtml jhtml pl sh py cgi exe application gadget hta cpl msc jar vb jse ws wsf wsc wsh " +
                                       "ps1 ps2 psc1 psc2 msh msh1 msh2 inf reg scf msp scr dll msi vbs bat com pif cmd vxd cpl htpasswd htaccess",
                ALLOWED_UPLOADS = existingConfiguration?.ALLOWED_UPLOADS ?? string.Empty,
                FILEPERMISSIONS = existingConfiguration?.FILEPERMISSIONS ?? "0644",
                DIRPERMISSIONS  = existingConfiguration?.DIRPERMISSIONS ?? "0755",
                LANG            = existingConfiguration?.LANG ?? _workContext.WorkingLanguage.UniqueSeoCode,
                DATEFORMAT      = existingConfiguration?.DATEFORMAT ?? "dd/MM/yyyy HH:mm",
                OPEN_LAST_DIR   = existingConfiguration?.OPEN_LAST_DIR ?? "yes",

                //no need user to configure
                INTEGRATION       = "tinymce4",
                RETURN_URL_PREFIX = currentPathBase,
                DIRLIST           = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=DIRLIST",
                CREATEDIR         = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=CREATEDIR",
                DELETEDIR         = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=DELETEDIR",
                MOVEDIR           = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=MOVEDIR",
                COPYDIR           = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=COPYDIR",
                RENAMEDIR         = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=RENAMEDIR",
                FILESLIST         = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=FILESLIST",
                UPLOAD            = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=UPLOAD",
                DOWNLOAD          = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=DOWNLOAD",
                DOWNLOADDIR       = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=DOWNLOADDIR",
                DELETEFILE        = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=DELETEFILE",
                MOVEFILE          = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=MOVEFILE",
                COPYFILE          = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=COPYFILE",
                RENAMEFILE        = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=RENAMEFILE",
                GENERATETHUMB     = $"{currentPathBase}/Admin/RoxyFileman/ProcessRequest?a=GENERATETHUMB"
            };

            //save the file
            var text = JsonConvert.SerializeObject(configuration, Formatting.Indented);

            _fileProvider.WriteAllText(filePath, text, Encoding.UTF8);
        }