diff --git a/AssemblyVersion.cs b/AssemblyVersion.cs
index 6d847fb..f4260c6 100644
--- a/AssemblyVersion.cs
+++ b/AssemblyVersion.cs
@@ -16,5 +16,5 @@ using System.Reflection;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("3.0.4.568")]
-[assembly: AssemblyFileVersion("3.0.4.568")]
\ No newline at end of file
+[assembly: AssemblyVersion("3.0.4.569")]
+[assembly: AssemblyFileVersion("3.0.4.569")]
\ No newline at end of file
diff --git a/Core/Core.csproj b/Core/Core.csproj
index 367c12f..52c779b 100644
--- a/Core/Core.csproj
+++ b/Core/Core.csproj
@@ -111,6 +111,7 @@
+
diff --git a/Core/FilesStorageProvider.cs b/Core/FilesStorageProvider.cs
index c591a1c..98ab9f5 100644
--- a/Core/FilesStorageProvider.cs
+++ b/Core/FilesStorageProvider.cs
@@ -10,7 +10,7 @@ namespace ScrewTurn.Wiki {
///
/// Implements a Local Files Storage Provider.
///
- public class FilesStorageProvider : IFilesStorageProviderV30 {
+ public class FilesStorageProvider : ProviderBase, IFilesStorageProviderV30 {
private readonly ComponentInformation info = new ComponentInformation("Local Files Provider",
"Threeplicate Srl", Settings.WikiVersion, "http://www.screwturn.eu", null);
@@ -30,7 +30,7 @@ namespace ScrewTurn.Wiki {
private IHostV30 host;
private string GetFullPath(string finalChunk) {
- return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), finalChunk);
+ return Path.Combine(GetDataDirectory(host), finalChunk);
}
///
@@ -46,7 +46,7 @@ namespace ScrewTurn.Wiki {
this.host = host;
- if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
+ if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
}
@@ -116,7 +116,7 @@ namespace ScrewTurn.Wiki {
private string BuildFullPath(string partialPath) {
if(partialPath == null) partialPath = "";
partialPath = partialPath.Replace("/", Path.DirectorySeparatorChar.ToString()).TrimStart(Path.DirectorySeparatorChar);
- string up = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), UploadDirectory);
+ string up = Path.Combine(GetDataDirectory(host), UploadDirectory);
return CheckPath(Path.Combine(up, partialPath), up); // partialPath CANNOT start with "\" -> Path.Combine does not work
}
@@ -130,7 +130,7 @@ namespace ScrewTurn.Wiki {
private string BuildFullPathForAttachments(string partialPath) {
if(partialPath == null) partialPath = "";
partialPath = partialPath.Replace("/", Path.DirectorySeparatorChar.ToString()).TrimStart(Path.DirectorySeparatorChar);
- string up = Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), AttachmentsDirectory);
+ string up = Path.Combine(GetDataDirectory(host), AttachmentsDirectory);
return CheckPath(Path.Combine(up, partialPath), up); // partialPath CANNOT start with "\" -> Path.Combine does not work
}
diff --git a/Core/PagesStorageProvider.cs b/Core/PagesStorageProvider.cs
index 6fb5fda..15525f8 100644
--- a/Core/PagesStorageProvider.cs
+++ b/Core/PagesStorageProvider.cs
@@ -12,7 +12,7 @@ namespace ScrewTurn.Wiki {
///
/// Implements a Pages Storage Provider.
///
- public class PagesStorageProvider : IPagesStorageProviderV30 {
+ public class PagesStorageProvider : ProviderBase, IPagesStorageProviderV30 {
private const string NamespacesFile = "Namespaces.cs";
private const string PagesFile = "Pages.cs";
@@ -40,15 +40,15 @@ namespace ScrewTurn.Wiki {
private IndexStorerBase indexStorer;
private string GetFullPath(string filename) {
- return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), filename);
+ return Path.Combine(GetDataDirectory(host), filename);
}
private string GetFullPathForPageContent(string filename) {
- return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PagesDirectory), filename);
+ return Path.Combine(Path.Combine(GetDataDirectory(host), PagesDirectory), filename);
}
private string GetFullPathForPageDrafts(string filename) {
- return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), DraftsDirectory), filename);
+ return Path.Combine(Path.Combine(GetDataDirectory(host), DraftsDirectory), filename);
}
private string GetDraftFullPath(LocalPageInfo page) {
@@ -58,15 +58,15 @@ namespace ScrewTurn.Wiki {
}
private string GetFullPathForMessages(string filename) {
- return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), MessagesDirectory), filename);
+ return Path.Combine(Path.Combine(GetDataDirectory(host), MessagesDirectory), filename);
}
private string GetFullPathForSnippets(string filename) {
- return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), SnippetsDirectory), filename);
+ return Path.Combine(Path.Combine(GetDataDirectory(host), SnippetsDirectory), filename);
}
private string GetFullPathForContentTemplate(string filename) {
- return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), ContentTemplatesDirectory), filename);
+ return Path.Combine(Path.Combine(GetDataDirectory(host), ContentTemplatesDirectory), filename);
}
///
@@ -92,24 +92,24 @@ namespace ScrewTurn.Wiki {
this.host = host;
- if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
+ if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
}
- if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PagesDirectory))) {
- Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PagesDirectory));
+ if(!Directory.Exists(Path.Combine(GetDataDirectory(host), PagesDirectory))) {
+ Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), PagesDirectory));
}
- if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), MessagesDirectory))) {
- Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), MessagesDirectory));
+ if(!Directory.Exists(Path.Combine(GetDataDirectory(host), MessagesDirectory))) {
+ Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), MessagesDirectory));
}
- if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), SnippetsDirectory))) {
- Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), SnippetsDirectory));
+ if(!Directory.Exists(Path.Combine(GetDataDirectory(host), SnippetsDirectory))) {
+ Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), SnippetsDirectory));
}
- if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), ContentTemplatesDirectory))) {
- Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), ContentTemplatesDirectory));
+ if(!Directory.Exists(Path.Combine(GetDataDirectory(host), ContentTemplatesDirectory))) {
+ Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), ContentTemplatesDirectory));
}
- if(!Directory.Exists(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), DraftsDirectory))) {
- Directory.CreateDirectory(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), DraftsDirectory));
+ if(!Directory.Exists(Path.Combine(GetDataDirectory(host), DraftsDirectory))) {
+ Directory.CreateDirectory(Path.Combine(GetDataDirectory(host), DraftsDirectory));
}
bool upgradeNeeded = false;
diff --git a/Core/ProviderBase.cs b/Core/ProviderBase.cs
new file mode 100644
index 0000000..bd1b466
--- /dev/null
+++ b/Core/ProviderBase.cs
@@ -0,0 +1,46 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ScrewTurn.Wiki.PluginFramework;
+
+namespace ScrewTurn.Wiki {
+
+ ///
+ /// Implements a base class for local file-based data providers.
+ ///
+ public abstract class ProviderBase {
+
+ private object _syncLock = new object();
+
+ private bool _dataDirectoryAlreadyRead = false;
+ private string _dataDirectory = null;
+
+ ///
+ /// Sets the data directory.
+ ///
+ /// The data directory.
+ protected void SetDataDirectory(string dataDirectory) {
+ lock(_syncLock) {
+ if(_dataDirectoryAlreadyRead) throw new InvalidOperationException("Cannot set data directory when it's already been read");
+ _dataDirectory = dataDirectory;
+ }
+ }
+
+ ///
+ /// Gets the data directory.
+ ///
+ /// The host object.
+ /// The data directory.
+ protected string GetDataDirectory(IHostV30 host) {
+ lock(_syncLock) {
+ _dataDirectoryAlreadyRead = true;
+ if(string.IsNullOrEmpty(_dataDirectory)) return host.GetSettingValue(SettingName.PublicDirectory);
+ else return _dataDirectory;
+ }
+ }
+
+ }
+
+}
diff --git a/Core/SettingsStorageProvider.cs b/Core/SettingsStorageProvider.cs
index 63c237b..2f8a4c1 100644
--- a/Core/SettingsStorageProvider.cs
+++ b/Core/SettingsStorageProvider.cs
@@ -11,7 +11,7 @@ namespace ScrewTurn.Wiki {
///
/// Implements a Settings Storage Provider against local text pluginAssemblies.
///
- public class SettingsStorageProvider : ISettingsStorageProviderV30 {
+ public class SettingsStorageProvider : ProviderBase, ISettingsStorageProviderV30 {
// Filenames: Settings, Log, RecentChanges, MetaData
private const string ConfigFile = "Config.cs";
@@ -62,15 +62,15 @@ namespace ScrewTurn.Wiki {
private bool isFirstStart = false;
private string GetFullPath(string name) {
- return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), name);
+ return Path.Combine(GetDataDirectory(host), name);
}
private string GetFullPathForPlugin(string name) {
- return Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PluginsDirectory), name);
+ return Path.Combine(Path.Combine(GetDataDirectory(host), PluginsDirectory), name);
}
private string GetFullPathForPluginConfig(string name) {
- return Path.Combine(Path.Combine(Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), PluginsDirectory), PluginsConfigDirectory), name);
+ return Path.Combine(Path.Combine(Path.Combine(GetDataDirectory(host), PluginsDirectory), PluginsConfigDirectory), name);
}
///
@@ -86,7 +86,7 @@ namespace ScrewTurn.Wiki {
this.host = host;
- if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
+ if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
}
diff --git a/Core/UsersStorageProvider.cs b/Core/UsersStorageProvider.cs
index c622bb0..fb5cd73 100644
--- a/Core/UsersStorageProvider.cs
+++ b/Core/UsersStorageProvider.cs
@@ -10,7 +10,7 @@ namespace ScrewTurn.Wiki {
///
/// Implements a Users Storage Provider.
///
- public class UsersStorageProvider : IUsersStorageProviderV30 {
+ public class UsersStorageProvider : ProviderBase, IUsersStorageProviderV30 {
private const string UsersFile = "Users.cs";
private const string UsersDataFile = "UsersData.cs";
@@ -25,7 +25,7 @@ namespace ScrewTurn.Wiki {
private UserInfo[] usersCache = null;
private string GetFullPath(string filename) {
- return Path.Combine(host.GetSettingValue(SettingName.PublicDirectory), filename);
+ return Path.Combine(GetDataDirectory(host), filename);
}
///
@@ -41,7 +41,7 @@ namespace ScrewTurn.Wiki {
this.host = host;
- if(!LocalProvidersTools.CheckWritePermissions(host.GetSettingValue(SettingName.PublicDirectory))) {
+ if(!LocalProvidersTools.CheckWritePermissions(GetDataDirectory(host))) {
throw new InvalidConfigurationException("Cannot write into the public directory - check permissions");
}