/// <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, ISmiFileProvider fileProvider = null) { Singleton <DataSettings> .Instance = settings ?? throw new ArgumentNullException(nameof(settings)); fileProvider ??= CommonHelper.DefaultFileProvider; var filePath = fileProvider.MapPath(SmiDataSettingsDefaults.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); }
/// <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 ?? SmiRoxyFilemanDefaults.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 ?? _mediaSettings.MaximumImageSize.ToString(), MAX_IMAGE_HEIGHT = existingConfiguration?.MAX_IMAGE_HEIGHT ?? _mediaSettings.MaximumImageSize.ToString(), 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); }