From 70502cd8815410b310359e475e61ac77b9821396 Mon Sep 17 00:00:00 2001 From: Sean Long Date: Fri, 17 Apr 2020 16:25:00 -0400 Subject: [PATCH 1/4] OS independent file paths --- .gitignore | 1 + Oqtane.Client/Services/FileService.cs | 4 ++-- Oqtane.Client/Services/FolderService.cs | 4 ++-- Oqtane.Server/Controllers/FileController.cs | 24 ++++++++++--------- Oqtane.Server/Controllers/FolderController.cs | 5 ++-- .../Controllers/ModuleDefinitionController.cs | 10 ++++---- Oqtane.Server/Controllers/ThemeController.cs | 2 +- Oqtane.Server/Controllers/UserController.cs | 4 ++-- .../Infrastructure/DatabaseManager.cs | 4 ++-- .../Infrastructure/InstallationManager.cs | 2 +- .../SiteTemplates/DefaultSiteTemplate.cs | 11 +++++---- Oqtane.Server/Repository/SiteRepository.cs | 2 +- Oqtane.Upgrade/Program.cs | 4 ++-- 13 files changed, 41 insertions(+), 36 deletions(-) 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)) { From ce118096b7df9e133b9011a411e86eba21502be6 Mon Sep 17 00:00:00 2001 From: Sean Long Date: Sat, 18 Apr 2020 12:53:41 -0400 Subject: [PATCH 2/4] Updated for consistant delimiter presence with source --- Oqtane.Server/Controllers/FileController.cs | 6 +++--- Oqtane.Server/Controllers/FolderController.cs | 4 ++-- Oqtane.Server/Controllers/ModuleDefinitionController.cs | 4 ++-- Oqtane.Server/Controllers/UserController.cs | 6 ++++-- Oqtane.Server/Infrastructure/DatabaseManager.cs | 5 +++-- Oqtane.Server/Infrastructure/InstallationManager.cs | 3 ++- .../Infrastructure/SiteTemplates/DefaultSiteTemplate.cs | 2 +- 7 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 5b22b062..5e57e3e5 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -431,12 +431,12 @@ namespace Oqtane.Controllers private string GetFolderPath(Folder folder) { - return Path.Combine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path, " ").TrimEnd(' '); + return Path.Combine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path); } private string GetFolderPath(string folder) { - return Path.Combine(_environment.WebRootPath, folder, " ").TrimEnd(' '); + return Path.Combine(_environment.WebRootPath, folder); } private void CreateDirectory(string folderpath) @@ -448,7 +448,7 @@ namespace Oqtane.Controllers string[] folders = folderpath.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (string folder in folders) { - path = Path.Combine(path, folder); + path = Path.Combine(path, folder," ").TrimEnd(' '); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); diff --git a/Oqtane.Server/Controllers/FolderController.cs b/Oqtane.Server/Controllers/FolderController.cs index a1e48fc1..b74fcdde 100644 --- a/Oqtane.Server/Controllers/FolderController.cs +++ b/Oqtane.Server/Controllers/FolderController.cs @@ -110,7 +110,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = Path.Combine(parent.Path, folder.Name); + folder.Path = Path.Combine(parent.Path, folder.Name," ").TrimEnd(' '); } folder = _folders.AddFolder(folder); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Folder Added {Folder}", folder); @@ -135,7 +135,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = Path.Combine(parent.Path, folder.Name); + folder.Path = Path.Combine(parent.Path, folder.Name, " ").TrimEnd(' '); } 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 03e1937f..ce6a7001 100644 --- a/Oqtane.Server/Controllers/ModuleDefinitionController.cs +++ b/Oqtane.Server/Controllers/ModuleDefinitionController.cs @@ -193,13 +193,13 @@ namespace Oqtane.Controllers if (moduleDefinition.Template == "internal") { - rootPath = rootFolder.FullName; + rootPath = Path.Combine(rootFolder.FullName," ").TrimEnd(' '); 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 = Path.Combine(rootFolder.Parent.FullName , moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module"); + rootPath = Path.Combine(rootFolder.Parent.FullName , moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module", " ").TrimEnd(' '); 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"; } diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index dfcb5b48..fe1da778 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -13,6 +13,7 @@ using System.Net; using Oqtane.Enums; using Oqtane.Infrastructure; using Oqtane.Repository; +using System.IO; namespace Oqtane.Controllers { @@ -150,7 +151,8 @@ namespace Oqtane.Controllers } // add folder for user - Folder folder = _folders.GetFolder(user.SiteId, "Users"); + string usersPath = Path.Combine("Users"," ").TrimEnd(' '); + Folder folder = _folders.GetFolder(user.SiteId, usersPath); if (folder != null) { _folders.AddFolder(new Folder @@ -158,7 +160,7 @@ namespace Oqtane.Controllers SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", - Path = System.IO.Path.Combine(folder.Path, newUser.UserId.ToString()), + Path = Path.Combine(folder.Path, newUser.UserId.ToString(), " ").TrimEnd(' '), 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 40f30092..a51c0238 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -387,14 +387,15 @@ namespace Oqtane.Infrastructure } // add folder for user - var folder = folderRepository.GetFolder(user.SiteId, "Users"); + string usersPath = Path.Combine("Users", " ").TrimEnd(' '); + var folder = folderRepository.GetFolder(user.SiteId, usersPath); if (folder != null) folderRepository.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", - Path = Path.Combine(folder.Path, newUser.UserId.ToString()), + Path = Path.Combine(folder.Path, newUser.UserId.ToString(), " ").TrimEnd(' '), Order = 1, IsSystem = true, Permissions = new List diff --git a/Oqtane.Server/Infrastructure/InstallationManager.cs b/Oqtane.Server/Infrastructure/InstallationManager.cs index f37d719e..21121689 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -103,7 +103,8 @@ namespace Oqtane.Infrastructure case ".svg": case ".js": case ".css": - filename = Path.Combine(sourceFolder, entry.FullName.Replace("wwwroot", name)); + string entryPath = Path.Combine(entry.FullName.Replace("wwwroot", name).Split("/")); + filename = Path.Combine(sourceFolder, entryPath); 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 150373a2..26dfaed0 100644 --- a/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs +++ b/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs @@ -134,7 +134,7 @@ namespace Oqtane.SiteTemplates if (System.IO.File.Exists(Path.Combine(_environment.WebRootPath, "images", "logo.png"))) { - string folderpath = Path.Combine(_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()," ").TrimEnd(); System.IO.Directory.CreateDirectory(folderpath); if (!System.IO.File.Exists(Path.Combine(folderpath, "logo.png"))) { From c07ebdd41b691afd942bb5c731147394412653e3 Mon Sep 17 00:00:00 2001 From: Sean Long Date: Sat, 18 Apr 2020 12:54:12 -0400 Subject: [PATCH 3/4] Revert "Updated for consistant delimiter presence with source" This reverts commit ce118096b7df9e133b9011a411e86eba21502be6. --- Oqtane.Server/Controllers/FileController.cs | 6 +++--- Oqtane.Server/Controllers/FolderController.cs | 4 ++-- Oqtane.Server/Controllers/ModuleDefinitionController.cs | 4 ++-- Oqtane.Server/Controllers/UserController.cs | 6 ++---- Oqtane.Server/Infrastructure/DatabaseManager.cs | 5 ++--- Oqtane.Server/Infrastructure/InstallationManager.cs | 3 +-- .../Infrastructure/SiteTemplates/DefaultSiteTemplate.cs | 2 +- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 5e57e3e5..5b22b062 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -431,12 +431,12 @@ namespace Oqtane.Controllers private string GetFolderPath(Folder folder) { - return Path.Combine(_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) @@ -448,7 +448,7 @@ namespace Oqtane.Controllers string[] folders = folderpath.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (string folder in folders) { - path = Path.Combine(path, folder," ").TrimEnd(' '); + 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 b74fcdde..a1e48fc1 100644 --- a/Oqtane.Server/Controllers/FolderController.cs +++ b/Oqtane.Server/Controllers/FolderController.cs @@ -110,7 +110,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = Path.Combine(parent.Path, folder.Name," ").TrimEnd(' '); + folder.Path = Path.Combine(parent.Path, folder.Name); } folder = _folders.AddFolder(folder); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Folder Added {Folder}", folder); @@ -135,7 +135,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = Path.Combine(parent.Path, folder.Name, " ").TrimEnd(' '); + 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 ce6a7001..03e1937f 100644 --- a/Oqtane.Server/Controllers/ModuleDefinitionController.cs +++ b/Oqtane.Server/Controllers/ModuleDefinitionController.cs @@ -193,13 +193,13 @@ namespace Oqtane.Controllers if (moduleDefinition.Template == "internal") { - rootPath = Path.Combine(rootFolder.FullName," ").TrimEnd(' '); + 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 = Path.Combine(rootFolder.Parent.FullName , moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module", " ").TrimEnd(' '); + 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"; } diff --git a/Oqtane.Server/Controllers/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index fe1da778..dfcb5b48 100644 --- a/Oqtane.Server/Controllers/UserController.cs +++ b/Oqtane.Server/Controllers/UserController.cs @@ -13,7 +13,6 @@ using System.Net; using Oqtane.Enums; using Oqtane.Infrastructure; using Oqtane.Repository; -using System.IO; namespace Oqtane.Controllers { @@ -151,8 +150,7 @@ namespace Oqtane.Controllers } // add folder for user - string usersPath = Path.Combine("Users"," ").TrimEnd(' '); - Folder folder = _folders.GetFolder(user.SiteId, usersPath); + Folder folder = _folders.GetFolder(user.SiteId, "Users"); if (folder != null) { _folders.AddFolder(new Folder @@ -160,7 +158,7 @@ namespace Oqtane.Controllers SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", - Path = Path.Combine(folder.Path, newUser.UserId.ToString(), " ").TrimEnd(' '), + 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 a51c0238..40f30092 100644 --- a/Oqtane.Server/Infrastructure/DatabaseManager.cs +++ b/Oqtane.Server/Infrastructure/DatabaseManager.cs @@ -387,15 +387,14 @@ namespace Oqtane.Infrastructure } // add folder for user - string usersPath = Path.Combine("Users", " ").TrimEnd(' '); - var folder = folderRepository.GetFolder(user.SiteId, usersPath); + var folder = folderRepository.GetFolder(user.SiteId, "Users"); if (folder != null) folderRepository.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", - Path = Path.Combine(folder.Path, newUser.UserId.ToString(), " ").TrimEnd(' '), + 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 21121689..f37d719e 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -103,8 +103,7 @@ namespace Oqtane.Infrastructure case ".svg": case ".js": case ".css": - string entryPath = Path.Combine(entry.FullName.Replace("wwwroot", name).Split("/")); - filename = Path.Combine(sourceFolder, entryPath); + 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 26dfaed0..150373a2 100644 --- a/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs +++ b/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs @@ -134,7 +134,7 @@ namespace Oqtane.SiteTemplates if (System.IO.File.Exists(Path.Combine(_environment.WebRootPath, "images", "logo.png"))) { - string folderpath = Path.Combine(_environment.ContentRootPath, "Content", "Tenants", site.TenantId.ToString(), "Sites", site.SiteId.ToString()," ").TrimEnd(); + 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(Path.Combine(folderpath, "logo.png"))) { From f0043f53eefac457f15c5b7a2d7622d993a2bae5 Mon Sep 17 00:00:00 2001 From: Sean Long Date: Sat, 18 Apr 2020 14:57:31 -0400 Subject: [PATCH 4/4] OS independent file paths & Utility.PathCombine added System.IO.Path.Combine provides cross-platform support for system paths, however rooted paths discarding of earlier segments Utilities.PathCombine ensures if any parameters start with root chacters does not discard previous Utilities.PathCombine allows appending of "\\" to translate to the correct cross-platform result --- Oqtane.Client/Services/FileService.cs | 2 +- Oqtane.Client/Services/FolderService.cs | 2 +- Oqtane.Server/Controllers/FileController.cs | 6 +++--- Oqtane.Server/Controllers/FolderController.cs | 4 ++-- .../Controllers/ModuleDefinitionController.cs | 8 ++++---- Oqtane.Server/Controllers/UserController.cs | 4 ++-- Oqtane.Server/Infrastructure/DatabaseManager.cs | 4 ++-- .../Infrastructure/InstallationManager.cs | 3 ++- .../SiteTemplates/DefaultSiteTemplate.cs | 2 +- Oqtane.Server/Repository/SiteRepository.cs | 3 ++- Oqtane.Shared/Shared/Utilities.cs | 17 +++++++++++++++++ 11 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Oqtane.Client/Services/FileService.cs b/Oqtane.Client/Services/FileService.cs index c073a460..871a123f 100644 --- a/Oqtane.Client/Services/FileService.cs +++ b/Oqtane.Client/Services/FileService.cs @@ -44,7 +44,7 @@ namespace Oqtane.Services { if (!(folderPath.EndsWith(System.IO.Path.DirectorySeparatorChar) || folderPath.EndsWith(System.IO.Path.AltDirectorySeparatorChar))) { - folderPath = System.IO.Path.Combine(folderPath, " ").TrimEnd(' '); + folderPath = Utilities.PathCombine(folderPath,"\\"); } var path = WebUtility.UrlEncode(folderPath); diff --git a/Oqtane.Client/Services/FolderService.cs b/Oqtane.Client/Services/FolderService.cs index 6c3fd69d..0446b285 100644 --- a/Oqtane.Client/Services/FolderService.cs +++ b/Oqtane.Client/Services/FolderService.cs @@ -40,7 +40,7 @@ namespace Oqtane.Services { if (!(folderPath.EndsWith(System.IO.Path.DirectorySeparatorChar) || folderPath.EndsWith(System.IO.Path.AltDirectorySeparatorChar))) { - folderPath = System.IO.Path.Combine(folderPath, " ").TrimEnd(' '); + folderPath = Utilities.PathCombine(folderPath, "\\"); } var path = WebUtility.UrlEncode(folderPath); diff --git a/Oqtane.Server/Controllers/FileController.cs b/Oqtane.Server/Controllers/FileController.cs index 5b22b062..d6e94644 100644 --- a/Oqtane.Server/Controllers/FileController.cs +++ b/Oqtane.Server/Controllers/FileController.cs @@ -431,12 +431,12 @@ namespace Oqtane.Controllers private string GetFolderPath(Folder folder) { - return Path.Combine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path, " ").TrimEnd(' '); + return Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", _tenants.GetTenant().TenantId.ToString(), "Sites", folder.SiteId.ToString(), folder.Path); } private string GetFolderPath(string folder) { - return Path.Combine(_environment.WebRootPath, folder, " ").TrimEnd(' '); + return Utilities.PathCombine(_environment.WebRootPath, folder); } private void CreateDirectory(string folderpath) @@ -448,7 +448,7 @@ namespace Oqtane.Controllers string[] folders = folderpath.Split(separators, StringSplitOptions.RemoveEmptyEntries); foreach (string folder in folders) { - path = Path.Combine(path, folder); + path = Utilities.PathCombine(path, folder,"\\"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); diff --git a/Oqtane.Server/Controllers/FolderController.cs b/Oqtane.Server/Controllers/FolderController.cs index a1e48fc1..55c19039 100644 --- a/Oqtane.Server/Controllers/FolderController.cs +++ b/Oqtane.Server/Controllers/FolderController.cs @@ -110,7 +110,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = Path.Combine(parent.Path, folder.Name); + folder.Path = Utilities.PathCombine(parent.Path, folder.Name,"\\"); } folder = _folders.AddFolder(folder); _logger.Log(LogLevel.Information, this, LogFunction.Create, "Folder Added {Folder}", folder); @@ -135,7 +135,7 @@ namespace Oqtane.Controllers if (string.IsNullOrEmpty(folder.Path) && folder.ParentId != null) { Folder parent = _folders.GetFolder(folder.ParentId.Value); - folder.Path = Path.Combine(parent.Path, folder.Name); + folder.Path = Utilities.PathCombine(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 03e1937f..4535b6f7 100644 --- a/Oqtane.Server/Controllers/ModuleDefinitionController.cs +++ b/Oqtane.Server/Controllers/ModuleDefinitionController.cs @@ -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," ").TrimEnd(' '); + string templatePath = Utilities.PathCombine(rootFolder.FullName, "Oqtane.Client", "Modules", "Admin", "ModuleCreator", "Templates",moduleDefinition.Template,"\\"); if (moduleDefinition.Template == "internal") { - rootPath = rootFolder.FullName; + rootPath = Utilities.PathCombine(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 = Path.Combine(rootFolder.Parent.FullName , moduleDefinition.Owner + "." + moduleDefinition.Name + "s.Module"); + rootPath = Utilities.PathCombine(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 = Path.Combine(rootPath, current.FullName.Replace(templatePath, "")); + string folderPath = Utilities.PathCombine(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/UserController.cs b/Oqtane.Server/Controllers/UserController.cs index dfcb5b48..bfba1459 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, Utilities.PathCombine("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 = System.IO.Path.Combine(folder.Path, newUser.UserId.ToString()), + Path = Utilities.PathCombine(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 838dd582..5ca2eaa2 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, Utilities.PathCombine("Users","\\")); if (folder != null) folderRepository.AddFolder(new Folder { SiteId = folder.SiteId, ParentId = folder.FolderId, Name = "My Folder", - Path = Path.Combine(folder.Path, newUser.UserId.ToString()), + Path = Utilities.PathCombine(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 f37d719e..4cfbaa6b 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -103,7 +103,8 @@ namespace Oqtane.Infrastructure case ".svg": case ".js": case ".css": - filename = Path.Combine(sourceFolder, entry.FullName.Replace("wwwroot", name)); + string entryPath = Utilities.PathCombine(entry.FullName.Replace("wwwroot", name).Split('/')); + filename = Path.Combine(sourceFolder, entryPath); 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 150373a2..91f4bc39 100644 --- a/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs +++ b/Oqtane.Server/Infrastructure/SiteTemplates/DefaultSiteTemplate.cs @@ -134,7 +134,7 @@ namespace Oqtane.SiteTemplates if (System.IO.File.Exists(Path.Combine(_environment.WebRootPath, "images", "logo.png"))) { - string folderpath = Path.Combine(_environment.ContentRootPath, "Content", "Tenants", site.TenantId.ToString(), "Sites", site.SiteId.ToString()); + string folderpath = Utilities.PathCombine(_environment.ContentRootPath, "Content", "Tenants", site.TenantId.ToString(), "Sites", site.SiteId.ToString(),"\\"); System.IO.Directory.CreateDirectory(folderpath); if (!System.IO.File.Exists(Path.Combine(folderpath, "logo.png"))) { diff --git a/Oqtane.Server/Repository/SiteRepository.cs b/Oqtane.Server/Repository/SiteRepository.cs index 2d5db9e7..4405536a 100644 --- a/Oqtane.Server/Repository/SiteRepository.cs +++ b/Oqtane.Server/Repository/SiteRepository.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Reflection; using Microsoft.EntityFrameworkCore; @@ -583,7 +584,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 = Utilities.PathCombine("Users","\\"), Order = 1, IsSystem = true, Permissions = "[{\"PermissionName\":\"Browse\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"View\",\"Permissions\":\"Administrators\"},{\"PermissionName\":\"Edit\",\"Permissions\":\"Administrators\"}]" }); diff --git a/Oqtane.Shared/Shared/Utilities.cs b/Oqtane.Shared/Shared/Utilities.cs index 662d524d..0f7d603d 100644 --- a/Oqtane.Shared/Shared/Utilities.cs +++ b/Oqtane.Shared/Shared/Utilities.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.IO; using System.Text; using System.Text.RegularExpressions; @@ -236,5 +237,21 @@ namespace Oqtane.Shared @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-0-9a-z]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$", RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)); } + + public static string PathCombine(params string[] segments) + { + var separators = new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }; + + for (int i =1;i < segments.Length; i++){ + if(Path.IsPathRooted(segments[i])){ + segments[i] = segments[i].TrimStart(separators); + if(String.IsNullOrEmpty(segments[i])){ + segments[i]=" "; + } + } + } + + return Path.Combine(segments).TrimEnd(); + } } }