diff --git a/.gitignore b/.gitignore index 33c751ad..8f8f91ba 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ Oqtane.Server/appsettings.json Oqtane.Server/Data/*.mdf Oqtane.Server/Data/*.ldf +/Oqtane.Server/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/Oqtane.Client/Services/FileService.cs b/Oqtane.Client/Services/FileService.cs index 09389f1e..c073a460 100644 --- a/Oqtane.Client/Services/FileService.cs +++ b/Oqtane.Client/Services/FileService.cs @@ -42,9 +42,9 @@ namespace Oqtane.Services public async Task> GetFilesAsync(int siteId, string folderPath) { - if (!folderPath.EndsWith("\\")) + if (!(folderPath.EndsWith(System.IO.Path.DirectorySeparatorChar) || folderPath.EndsWith(System.IO.Path.AltDirectorySeparatorChar))) { - folderPath += "\\"; + folderPath = System.IO.Path.Combine(folderPath, " ").TrimEnd(' '); } var path = WebUtility.UrlEncode(folderPath); diff --git a/Oqtane.Client/Services/FolderService.cs b/Oqtane.Client/Services/FolderService.cs index 9d63ae8d..6c3fd69d 100644 --- a/Oqtane.Client/Services/FolderService.cs +++ b/Oqtane.Client/Services/FolderService.cs @@ -38,9 +38,9 @@ namespace Oqtane.Services public async Task GetFolderAsync(int siteId, [NotNull] string folderPath) { - if (!folderPath.EndsWith("\\")) + if (!(folderPath.EndsWith(System.IO.Path.DirectorySeparatorChar) || folderPath.EndsWith(System.IO.Path.AltDirectorySeparatorChar))) { - folderPath += "\\"; + folderPath = System.IO.Path.Combine(folderPath, " ").TrimEnd(' '); } var path = WebUtility.UrlEncode(folderPath); diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 71095f2d..5b22b062 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -161,7 +161,7 @@ namespace Oqtane.Controllers { _files.DeleteFile(id); - string filepath = Path.Combine(GetFolderPath(file.Folder) + file.Name); + string filepath = Path.Combine(GetFolderPath(file.Folder), file.Name); if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); @@ -199,14 +199,15 @@ namespace Oqtane.Controllers try { var client = new WebClient(); + string targetPath = Path.Combine(folderPath, filename); // remove file if it already exists - if (System.IO.File.Exists(folderPath + filename)) + if (System.IO.File.Exists(targetPath)) { - System.IO.File.Delete(folderPath + filename); + System.IO.File.Delete(targetPath); } - client.DownloadFile(url, folderPath + filename); - _files.AddFile(CreateFile(filename, folder.FolderId, folderPath + filename)); + client.DownloadFile(url, targetPath); + _files.AddFile(CreateFile(filename, folder.FolderId, targetPath)); } catch { @@ -262,7 +263,7 @@ namespace Oqtane.Controllers string upload = await MergeFile(folderPath, file.FileName); if (upload != "" && folderId != -1) { - _files.AddFile(CreateFile(upload, folderId, folderPath + upload)); + _files.AddFile(CreateFile(upload, folderId, Path.Combine(folderPath, upload))); } } else @@ -400,7 +401,7 @@ namespace Oqtane.Controllers { if (_userPermissions.IsAuthorized(User, PermissionNames.View, file.Folder.Permissions)) { - string filepath = GetFolderPath(file.Folder) + file.Name; + string filepath = Path.Combine(GetFolderPath(file.Folder) , file.Name); if (System.IO.File.Exists(filepath)) { byte[] filebytes = System.IO.File.ReadAllBytes(filepath); @@ -430,12 +431,12 @@ namespace Oqtane.Controllers private string GetFolderPath(Folder folder) { - return _environment.ContentRootPath + "\\Content\\Tenants\\" + _tenants.GetTenant().TenantId.ToString() + "\\Sites\\" + folder.SiteId.ToString() + "\\" + folder.Path; + return Path.Combine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path, " ").TrimEnd(' '); } private string GetFolderPath(string folder) { - return Path.Combine(_environment.WebRootPath, folder); + return Path.Combine(_environment.WebRootPath, folder, " ").TrimEnd(' '); } private void CreateDirectory(string folderpath) @@ -443,10 +444,11 @@ namespace Oqtane.Controllers if (!Directory.Exists(folderpath)) { string path = ""; - string[] folders = folderpath.Split(new[] {'\\'}, StringSplitOptions.RemoveEmptyEntries); + var separators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; + string[] folders = folderpath.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (string folder in folders) { - path += folder + "\\"; + path = Path.Combine(path, folder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); diff --git a/Oqtane.Server/Controllers/FolderController.cs b/Oqtane.Server/Controllers/FolderController.cs index ee75a536..a1e48fc1 100644 --- a/Oqtane.Server/Controllers/FolderController.cs +++ b/Oqtane.Server/Controllers/FolderController.cs @@ -9,6 +9,7 @@ using Oqtane.Enums; using Oqtane.Infrastructure; using Oqtane.Repository; using Oqtane.Security; +using System.IO; namespace Oqtane.Controllers { @@ -109,7 +110,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = parent.Path + folder.Name + "\\"; + folder.Path = Path.Combine(parent.Path, folder.Name); } folder = _folders.AddFolder(folder); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Folder Added {Folder}", folder); @@ -134,7 +135,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = parent.Path + folder.Name + "\\"; + folder.Path = Path.Combine(parent.Path, folder.Name); } folder = _folders.UpdateFolder(folder); _logger.Log(LogLevel.Information, this, LogFunction.Update, "Folder Updated {Folder}", folder); diff --git a/Oqtane.Server/Controllers/ModuleDefinitionController.cs b/Oqtane.Server/Controllers/ModuleDefinitionController.cs index b197e62d..03e1937f 100644 --- a/Oqtane.Server/Controllers/ModuleDefinitionController.cs +++ b/Oqtane.Server/Controllers/ModuleDefinitionController.cs @@ -138,7 +138,7 @@ namespace Oqtane.Controllers assemblyname = assemblyname.Replace(".Server", ""); // clean up module static resource folder - string folder = Path.Combine(_environment.WebRootPath, "Modules\\" + assemblyname); + string folder = Path.Combine(_environment.WebRootPath, Path.Combine("Modules",assemblyname)); if (Directory.Exists(folder)) { Directory.Delete(folder, true); @@ -189,17 +189,17 @@ namespace Oqtane.Controllers { string rootPath; DirectoryInfo rootFolder = Directory.GetParent(_environment.ContentRootPath); - string templatePath = Path.Combine(rootFolder.FullName, "Oqtane.Client\\Modules\\Admin\\ModuleCreator\\Templates\\" + moduleDefinition.Template + "\\"); + string templatePath = Path.Combine(rootFolder.FullName, "Oqtane.Client", "Modules", "Admin", "ModuleCreator", "Templates",moduleDefinition.Template," ").TrimEnd(' '); if (moduleDefinition.Template == "internal") { - rootPath = rootFolder.FullName + "\\"; + rootPath = rootFolder.FullName; moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Modules, Oqtane.Client"; moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Manager." + moduleDefinition.Name + "Manager, Oqtane.Server"; } else { - rootPath = rootFolder.Parent.FullName + "\\" + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module\\"; + rootPath = Path.Combine(rootFolder.Parent.FullName , moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module"); moduleDefinition.ModuleDefinitionName = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Modules, " + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module.Client"; moduleDefinition.ServerManagerType = moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Manager." + moduleDefinition.Name + "Manager, " + moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module.Server"; } @@ -218,7 +218,7 @@ namespace Oqtane.Controllers private void ProcessTemplatesRecursively(DirectoryInfo current, string rootPath, string rootFolder, string templatePath, ModuleDefinition moduleDefinition) { // process folder - string folderPath = rootPath + current.FullName.Replace(templatePath, ""); + string folderPath = Path.Combine(rootPath, current.FullName.Replace(templatePath, "")); folderPath = folderPath.Replace("[Owner]", moduleDefinition.Owner); folderPath = folderPath.Replace("[Module]", moduleDefinition.Name); if (!Directory.Exists(folderPath)) diff --git a/Oqtane.Server/Controllers/ThemeController.cs b/Oqtane.Server/Controllers/ThemeController.cs index af7af8e1..5f516851 100644 --- a/Oqtane.Server/Controllers/ThemeController.cs +++ b/Oqtane.Server/Controllers/ThemeController.cs @@ -58,7 +58,7 @@ namespace Oqtane.Controllers { themename = theme.ThemeName.Substring(0, theme.ThemeName.IndexOf(",")); - string folder = Path.Combine(_environment.WebRootPath, "Themes\\" + themename); + string folder = Path.Combine(_environment.WebRootPath, "Themes" , themename); if (Directory.Exists(folder)) { Directory.Delete(folder, true); diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index c0cec6a8..dfcb5b48 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -150,7 +150,7 @@ namespace Oqtane.Controllers } // add folder for user - Folder folder = _folders.GetFolder(user.SiteId, "Users\\"); + Folder folder = _folders.GetFolder(user.SiteId, "Users"); if (folder != null) { _folders.AddFolder(new Folder @@ -158,7 +158,7 @@ namespace Oqtane.Controllers SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", - Path = folder.Path + newUser.UserId.ToString() + "\\", + Path = System.IO.Path.Combine(folder.Path, newUser.UserId.ToString()), Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"[" + newUser.UserId.ToString() + "]\"},{\"PermissionName\":\"View\",\"Permissions\":\"All Users\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"[" + diff --git a/Oqtane.Server/Infrastructure/DatabaseManager.cs b/Oqtane.Server/Infrastructure/DatabaseManager.cs index dabe8c78..40f30092 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -387,14 +387,14 @@ namespace Oqtane.Infrastructure } // add folder for user - var folder = folderRepository.GetFolder(user.SiteId, "Users\\"); + var folder = folderRepository.GetFolder(user.SiteId, "Users"); if (folder != null) folderRepository.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", - Path = folder.Path + newUser.UserId + "\\", + Path = Path.Combine(folder.Path, newUser.UserId.ToString()), Order = 1, IsSystem = true, Permissions = new List diff --git a/Oqtane.Server/Infrastructure/InstallationManager.cs b/Oqtane.Server/Infrastructure/InstallationManager.cs index a85fdcc7..f37d719e 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -103,7 +103,7 @@ namespace Oqtane.Infrastructure case ".svg": case ".js": case ".css": - filename = sourceFolder + "\\" + entry.FullName.Replace("wwwroot", name).Replace("/", "\\"); + filename = Path.Combine(sourceFolder, entry.FullName.Replace("wwwroot", name)); if (!Directory.Exists(Path.GetDirectoryName(filename))) { Directory.CreateDirectory(Path.GetDirectoryName(filename)); diff --git a/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs b/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs index daab95f1..150373a2 100644 --- a/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs +++ b/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using Oqtane.Repository; using Microsoft.AspNetCore.Hosting; using Oqtane.Shared; +using System.IO; namespace Oqtane.SiteTemplates { @@ -131,16 +132,16 @@ namespace Oqtane.SiteTemplates } }); - if (System.IO.File.Exists(_environment.WebRootPath + "\\images\\logo.png")) + if (System.IO.File.Exists(Path.Combine(_environment.WebRootPath, "images", "logo.png"))) { - string folderpath = _environment.ContentRootPath + "\\Content\\Tenants\\" + site.TenantId.ToString() + "\\Sites\\" + site.SiteId.ToString() + "\\"; + string folderpath = Path.Combine(_environment.ContentRootPath, "Content", "Tenants", site.TenantId.ToString(), "Sites", site.SiteId.ToString()); System.IO.Directory.CreateDirectory(folderpath); - if (!System.IO.File.Exists(folderpath + "logo.png")) + if (!System.IO.File.Exists(Path.Combine(folderpath, "logo.png"))) { - System.IO.File.Copy(_environment.WebRootPath + "\\images\\logo.png", folderpath + "logo.png"); + System.IO.File.Copy(Path.Combine(_environment.WebRootPath, "images", "logo.png"), Path.Combine(folderpath, "logo.png")); } Folder folder = _folderRepository.GetFolder(site.SiteId, ""); - File file = _fileRepository.AddFile(new File { FolderId = folder.FolderId, Name = "logo.png", Extension = "png", Size = 8192, ImageHeight = 80, ImageWidth = 250 }); + Oqtane.Models.File file = _fileRepository.AddFile(new Oqtane.Models.File { FolderId = folder.FolderId, Name = "logo.png", Extension = "png", Size = 8192, ImageHeight = 80, ImageWidth = 250 }); site.LogoFileId = file.FileId; _siteRepository.UpdateSite(site); } diff --git a/Oqtane.Server/Repository/SiteRepository.cs b/Oqtane.Server/Repository/SiteRepository.cs index 4cba5e20..2d5db9e7 100644 --- a/Oqtane.Server/Repository/SiteRepository.cs +++ b/Oqtane.Server/Repository/SiteRepository.cs @@ -583,7 +583,7 @@ namespace Oqtane.Repository }); _folderRepository.AddFolder(new Folder { - SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = "Users\\", Order = 1, IsSystem = true, + SiteId = site.SiteId, ParentId = folder.FolderId, Name = "Users", Path = "Users", Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]" }); diff --git a/Oqtane.Upgrade/Program.cs b/Oqtane.Upgrade/Program.cs index 8aa70d3b..f1f0f9b4 100644 --- a/Oqtane.Upgrade/Program.cs +++ b/Oqtane.Upgrade/Program.cs @@ -13,11 +13,11 @@ namespace Oqtane.Upgrade string binfolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); // assumes that the application executable must be deployed to the /bin of the Oqtane.Server project - if (binfolder.Contains("Oqtane.Server\\bin")) + if (binfolder.Contains(Path.Combine("Oqtane.Server", "bin"))) { // ie. binfolder = Oqtane.Server\bin\Debug\netcoreapp3.0\ string rootfolder = Directory.GetParent(binfolder).Parent.Parent.FullName; - string deployfolder = Path.Combine(rootfolder, "wwwroot\\Framework"); + string deployfolder = Path.Combine(rootfolder, Path.Combine("wwwroot","Framework")); if (Directory.Exists(deployfolder)) {