Skip to content

Commit

Permalink
BUG-2114: Fixed totaly f***ed up fix, this should be better.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakritzator committed Jan 18, 2017
1 parent 89ae948 commit 9e9d058
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
6 changes: 1 addition & 5 deletions Greenshot/Destinations/FileDestination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ private static string CreateNewFilename(ICaptureDetails captureDetails) {
pattern = "greenshot ${capturetime}";
}
string filename = FilenameHelper.GetFilenameFromPattern(pattern, CoreConfig.OutputFileFormat, captureDetails);
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC)
if (!File.Exists(CoreConfig.OutputFilePath))
{
CoreConfig.OutputFilePath = CoreConfig.GetDefault(nameof(CoreConfig.OutputFilePath)) as string;
}
CoreConfig.ValidateAndCorrectOutputFilePath();
string filepath = FilenameHelper.FillVariables(CoreConfig.OutputFilePath, false);
try {
fullPath = Path.Combine(filepath, filename);
Expand Down
8 changes: 1 addition & 7 deletions GreenshotPlugin/Controls/SaveImageFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,7 @@ private void Init() {
ApplyFilterOptions();
string initialDirectory = null;
try {
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC)
var outputFilePath = Path.GetDirectoryName(conf.OutputFileAsFullpath);
if (outputFilePath == null || (!File.Exists(conf.OutputFileAsFullpath) && !Directory.Exists(outputFilePath)))
{
conf.OutputFileAsFullpath = conf.GetDefault(nameof(conf.OutputFileAsFullpath)) as string;
}

conf.ValidateAndCorrectOutputFileAsFullpath();
initialDirectory = Path.GetDirectoryName(conf.OutputFileAsFullpath);
} catch {
LOG.WarnFormat("OutputFileAsFullpath was set to {0}, ignoring due to problem in path.", conf.OutputFileAsFullpath);
Expand Down
24 changes: 24 additions & 0 deletions GreenshotPlugin/Core/CoreConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,5 +515,29 @@ public override void AfterLoad() {
WebRequestReadWriteTimeout = 100;
}
}

/// <summary>
/// Validate the OutputFilePath, and if this is not correct it will be set to the default
/// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC)
/// </summary>
public void ValidateAndCorrectOutputFilePath()
{
if (!Directory.Exists(OutputFilePath))
{
OutputFilePath = GetDefault(nameof(OutputFilePath)) as string;
}
}
/// <summary>
/// Validate the OutputFileAsFullpath, and if this is not correct it will be set to the default
/// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC)
/// </summary>
public void ValidateAndCorrectOutputFileAsFullpath()
{
var outputFilePath = Path.GetDirectoryName(OutputFileAsFullpath);
if (outputFilePath == null || (!File.Exists(OutputFileAsFullpath) && !Directory.Exists(outputFilePath)))
{
OutputFileAsFullpath = GetDefault(nameof(OutputFileAsFullpath)) as string;
}
}
}
}

0 comments on commit 9e9d058

Please sign in to comment.