-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Enable user to override the default system paths for MyDocument & A…
…pplicationData from a configuration file. - Removed 'Sdl.Community.' from the assembly output names. - Bumped release version to 5.1.6.0 Details: Starting with this latest release, a new configuration file 'Qualitivity.config' is now unpacked in plugins folder (e.g. ...\Trados\Trados Studio\17\Plugins\Unpacked\Qualitivity\Qualitivity.config). You will find two new properties MyDocumentsPath & ApplicationDataPath that enable the user to override these default paths from the system. Note: It is possible to specify the same folder for both. If the folder/s specified are empty or not valid, then the default system path/s will be used. Example: (Qualitivity.dll.config) <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="MyDocumentsPath" value="C:\Temp\" /> <add key="ApplicationDataPath" value="C:\Temp\" /> </appSettings> </configuration>
- Loading branch information
1 parent
e423408
commit bec81ee
Showing
15 changed files
with
170 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 109 additions & 68 deletions
177
Qualitivity/Sdl.Community.Qualitivity.Models/Configuration/ApplicationPaths.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,115 @@ | ||
using System; | ||
using System.Configuration; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace Sdl.Community.Structures.Configuration | ||
{ | ||
[Serializable] | ||
public class ApplicationPaths : ICloneable | ||
{ | ||
public string ApplicationSettingsPath { get; set; } | ||
|
||
public string ApplicationTrackChangesPath { get; set; } | ||
public string ApplicationTrackChangesReportPath { get; set; } | ||
|
||
public string ApplicationMyDocumentsPath { get; set; } | ||
public string ApplicationMyDocumentsDatabasePath { get; set; } | ||
public string ApplicationMyDocumentsDatabaseSettingsPath { get; set; } | ||
public string ApplicationMyDocumentsDatabaseProjectsPath { get; set; } | ||
|
||
public string ApplicationBackupDatabasePath { get; set; } | ||
|
||
public ApplicationPaths() | ||
{ | ||
ApplicationSettingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Qualitivity"); | ||
if (!Directory.Exists(ApplicationSettingsPath)) | ||
Directory.CreateDirectory(ApplicationSettingsPath); | ||
|
||
|
||
ApplicationTrackChangesPath = Path.Combine(ApplicationSettingsPath, "Track.Changes"); | ||
if (!Directory.Exists(ApplicationTrackChangesPath)) | ||
Directory.CreateDirectory(ApplicationTrackChangesPath); | ||
|
||
ApplicationTrackChangesReportPath = Path.Combine(ApplicationTrackChangesPath, "Reports"); | ||
if (!Directory.Exists(ApplicationTrackChangesReportPath)) | ||
Directory.CreateDirectory(ApplicationTrackChangesReportPath); | ||
|
||
|
||
ApplicationMyDocumentsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Qualitivity"); | ||
if (!Directory.Exists(ApplicationMyDocumentsPath)) | ||
Directory.CreateDirectory(ApplicationMyDocumentsPath); | ||
ApplicationMyDocumentsDatabasePath = Path.Combine(ApplicationMyDocumentsPath, "Database"); | ||
if (!Directory.Exists(ApplicationMyDocumentsDatabasePath)) | ||
Directory.CreateDirectory(ApplicationMyDocumentsDatabasePath); | ||
ApplicationMyDocumentsDatabaseSettingsPath = Path.Combine(ApplicationMyDocumentsDatabasePath, "Settings.sqlite"); | ||
ApplicationMyDocumentsDatabaseProjectsPath = Path.Combine(ApplicationMyDocumentsDatabasePath, "Projects.sqlite"); | ||
|
||
|
||
|
||
|
||
ApplicationBackupDatabasePath = Path.Combine(ApplicationMyDocumentsDatabasePath, "Backups"); | ||
if (!Directory.Exists(ApplicationBackupDatabasePath)) | ||
Directory.CreateDirectory(ApplicationBackupDatabasePath); | ||
} | ||
|
||
public object Clone() | ||
{ | ||
var applicationPaths = new ApplicationPaths | ||
{ | ||
ApplicationSettingsPath = ApplicationSettingsPath, | ||
ApplicationTrackChangesPath = ApplicationTrackChangesPath, | ||
ApplicationTrackChangesReportPath = ApplicationTrackChangesReportPath, | ||
ApplicationMyDocumentsPath = ApplicationMyDocumentsPath, | ||
ApplicationMyDocumentsDatabasePath = ApplicationMyDocumentsDatabasePath, | ||
ApplicationBackupDatabasePath = ApplicationBackupDatabasePath | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
return applicationPaths; | ||
} | ||
} | ||
[Serializable] | ||
public class ApplicationPaths : ICloneable | ||
{ | ||
public string ApplicationSettingsPath { get; set; } | ||
|
||
public string ApplicationTrackChangesPath { get; set; } | ||
public string ApplicationTrackChangesReportPath { get; set; } | ||
|
||
public string ApplicationMyDocumentsPath { get; set; } | ||
public string ApplicationMyDocumentsDatabasePath { get; set; } | ||
public string ApplicationMyDocumentsDatabaseSettingsPath { get; set; } | ||
public string ApplicationMyDocumentsDatabaseProjectsPath { get; set; } | ||
|
||
public string ApplicationBackupDatabasePath { get; set; } | ||
|
||
const string MyDocumentsPath = "MyDocumentsPath"; | ||
const string ApplicationDataPath = "ApplicationDataPath"; | ||
|
||
public ApplicationPaths() | ||
{ | ||
var location = Assembly.GetExecutingAssembly().Location; | ||
var unpackedFolder = location.Substring(0, location.LastIndexOf("\\", StringComparison.Ordinal)); | ||
|
||
var assembly = Path.Combine(unpackedFolder, "Qualitivity.dll"); | ||
var config = ConfigurationManager.OpenExeConfiguration(assembly); | ||
|
||
var myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | ||
var applicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); | ||
|
||
if (config.AppSettings?.Settings != null) | ||
{ | ||
var myDocumentsPathCustom = GetConfigValue(config, MyDocumentsPath); | ||
if (myDocumentsPathCustom != null) | ||
{ | ||
myDocumentsPath = myDocumentsPathCustom; | ||
} | ||
|
||
var applicationDataPathCustom = GetConfigValue(config, ApplicationDataPath); | ||
if (applicationDataPathCustom != null) | ||
{ | ||
applicationDataPath = applicationDataPathCustom; | ||
} | ||
} | ||
|
||
ApplicationMyDocumentsPath = Path.Combine(myDocumentsPath, "Qualitivity"); | ||
if (!Directory.Exists(ApplicationMyDocumentsPath)) | ||
Directory.CreateDirectory(ApplicationMyDocumentsPath); | ||
|
||
ApplicationMyDocumentsDatabasePath = Path.Combine(ApplicationMyDocumentsPath, "Database"); | ||
if (!Directory.Exists(ApplicationMyDocumentsDatabasePath)) | ||
Directory.CreateDirectory(ApplicationMyDocumentsDatabasePath); | ||
|
||
ApplicationMyDocumentsDatabaseSettingsPath = Path.Combine(ApplicationMyDocumentsDatabasePath, "Settings.sqlite"); | ||
ApplicationMyDocumentsDatabaseProjectsPath = Path.Combine(ApplicationMyDocumentsDatabasePath, "Projects.sqlite"); | ||
|
||
ApplicationBackupDatabasePath = Path.Combine(ApplicationMyDocumentsDatabasePath, "Backups"); | ||
if (!Directory.Exists(ApplicationBackupDatabasePath)) | ||
Directory.CreateDirectory(ApplicationBackupDatabasePath); | ||
|
||
ApplicationSettingsPath = Path.Combine(applicationDataPath, "Qualitivity"); | ||
if (!Directory.Exists(ApplicationSettingsPath)) | ||
Directory.CreateDirectory(ApplicationSettingsPath); | ||
|
||
ApplicationTrackChangesPath = Path.Combine(ApplicationSettingsPath, "Track.Changes"); | ||
if (!Directory.Exists(ApplicationTrackChangesPath)) | ||
Directory.CreateDirectory(ApplicationTrackChangesPath); | ||
|
||
ApplicationTrackChangesReportPath = Path.Combine(ApplicationTrackChangesPath, "Reports"); | ||
if (!Directory.Exists(ApplicationTrackChangesReportPath)) | ||
Directory.CreateDirectory(ApplicationTrackChangesReportPath); | ||
} | ||
|
||
private static string GetConfigValue(System.Configuration.Configuration config, string propertyName) | ||
{ | ||
if (config.AppSettings.Settings.AllKeys.Any(a => a == propertyName)) | ||
{ | ||
var value = config.AppSettings.Settings[propertyName].Value; | ||
if (value != null && Directory.Exists(value)) | ||
{ | ||
return value; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public object Clone() | ||
{ | ||
var applicationPaths = new ApplicationPaths | ||
{ | ||
ApplicationSettingsPath = ApplicationSettingsPath, | ||
ApplicationTrackChangesPath = ApplicationTrackChangesPath, | ||
ApplicationTrackChangesReportPath = ApplicationTrackChangesReportPath, | ||
ApplicationMyDocumentsPath = ApplicationMyDocumentsPath, | ||
ApplicationMyDocumentsDatabasePath = ApplicationMyDocumentsDatabasePath, | ||
ApplicationBackupDatabasePath = ApplicationBackupDatabasePath | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
return applicationPaths; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<appSettings> | ||
<add key="MyDocumentsPath" value="C:\Temp\MyDocumentsPath" /> | ||
<add key="ApplicationDataPath" value="C:\Temp\ApplicationDataPath" /> | ||
</appSettings> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.