Added logic which forces the greenshot.ini to be created in the startup-path (where the executable is) when there is no log4net.xml available. This is useful when someone just wants to use the greenshot.exe

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1607 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-01-24 20:59:26 +00:00
commit 83570e855b
4 changed files with 28 additions and 5 deletions

View file

@ -48,6 +48,7 @@ namespace IniFile {
return portable;
}
}
/// <summary>
/// Initialize the ini config
/// </summary>
@ -59,7 +60,25 @@ namespace IniFile {
Reload();
WatchConfigFile(true);
}
public static void ForceIniInStartupPath() {
if (portableCheckMade) {
throw new Exception("ForceLocal should be called before any file is read");
}
portable = false;
portableCheckMade = true;
string applicationStartupPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
if (applicationName == null || configName == null) {
Init();
}
string forcedIni = Path.Combine(applicationStartupPath, applicationName + INI_EXTENSION);
if (!File.Exists(forcedIni)) {
using (File.Create(forcedIni)) {
}
}
}
/// <summary>
/// Default init
/// </summary>
@ -87,7 +106,7 @@ namespace IniFile {
// Monitor the ini file
watcher = new FileSystemWatcher();
watcher.Path = Path.GetDirectoryName(iniLocation);
watcher.Filter = "*.ini";
watcher.Filter = "greenshot.ini";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += new FileSystemEventHandler(ConfigFileChanged);
}
@ -158,7 +177,9 @@ namespace IniFile {
if (portable) {
string pafConfigPath = Path.Combine(applicationStartupPath, @"Data\Settings");
try {
Directory.CreateDirectory(pafConfigPath);
if (!Directory.Exists(pafConfigPath)) {
Directory.CreateDirectory(pafConfigPath);
}
iniFilePath = Path.Combine(pafConfigPath, configFilename);
} catch(Exception e) {
LOG.InfoFormat("Portable mode NOT possible, couldn't create directory '{0}'! Reason: {1}", pafConfigPath, e.Message);