BUG-2114 & BUG-1992: Hopefully implemented this more stable as it used to be.

This commit is contained in:
Robin 2017-01-13 19:46:54 +01:00
parent 73bdd0f405
commit 0b2cbe1c0b
4 changed files with 43 additions and 16 deletions

View file

@ -115,6 +115,11 @@ namespace Greenshot.Destinations {
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;
}
string filepath = FilenameHelper.FillVariables(CoreConfig.OutputFilePath, false);
try {
fullPath = Path.Combine(filepath, filename);

View file

@ -1307,6 +1307,11 @@ namespace Greenshot {
private void NotifyIconClick(ClickActions clickAction) {
switch (clickAction) {
case ClickActions.OPEN_LAST_IN_EXPLORER:
// 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(_conf.OutputFileAsFullpath))
{
_conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string;
}
string path = _conf.OutputFileAsFullpath;
if (!File.Exists(path)) {
string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath);
@ -1315,15 +1320,25 @@ namespace Greenshot {
}
}
if (path == null) {
// 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(_conf.OutputFilePath))
{
_conf.OutputFilePath = _conf.GetDefault(nameof(_conf.OutputFilePath)) as string;
}
string configPath = FilenameHelper.FillVariables(_conf.OutputFilePath, false);
if (Directory.Exists(configPath)) {
path = configPath;
}
}
ExplorerHelper.OpenInExplorer(path);
break;
case ClickActions.OPEN_LAST_IN_EDITOR:
// 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(_conf.OutputFileAsFullpath))
{
_conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string;
}
if (File.Exists(_conf.OutputFileAsFullpath)) {
CaptureHelper.CaptureFile(_conf.OutputFileAsFullpath, DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
}
@ -1342,9 +1357,21 @@ namespace Greenshot {
/// The Contextmenu_OpenRecent currently opens the last know save location
/// </summary>
private void Contextmenu_OpenRecent(object sender, EventArgs eventArgs) {
// 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(_conf.OutputFilePath))
{
_conf.OutputFilePath = _conf.GetDefault(nameof(_conf.OutputFilePath)) as string;
}
string path = FilenameHelper.FillVariables(_conf.OutputFilePath, false);
// Fix for #1470, problems with a drive which is no longer available
try {
// 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(_conf.OutputFileAsFullpath))
{
_conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string;
}
string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath);
if (lastFilePath != null && Directory.Exists(lastFilePath)) {

View file

@ -68,6 +68,12 @@ namespace GreenshotPlugin.Controls {
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)
if (!File.Exists(conf.OutputFileAsFullpath))
{
conf.OutputFileAsFullpath = conf.GetDefault(nameof(conf.OutputFileAsFullpath)) as string;
}
initialDirectory = Path.GetDirectoryName(conf.OutputFileAsFullpath);
} catch {
LOG.WarnFormat("OutputFileAsFullpath was set to {0}, ignoring due to problem in path.", conf.OutputFileAsFullpath);
@ -90,12 +96,12 @@ namespace GreenshotPlugin.Controls {
PrepareFilterOptions();
string fdf = "";
int preselect = 0;
var outputFileFormatAsString = Enum.GetName(typeof(OutputFormat), conf.OutputFileFormat);
var outputFileFormatAsString = Enum.GetName(typeof(OutputFormat), conf.OutputFileFormat);
for(int i=0; i<_filterOptions.Length; i++){
FilterOption fo = _filterOptions[i];
fdf += fo.Label + "|*." + fo.Extension + "|";
if(outputFileFormatAsString == fo.Extension)
preselect = i;
if(outputFileFormatAsString == fo.Extension)
preselect = i;
}
fdf = fdf.Substring(0, fdf.Length-1);
SaveFileDialog.Filter = fdf;

View file

@ -342,9 +342,8 @@ namespace GreenshotPlugin.Core {
case "OutputFileAsFullpath":
if (IniConfig.IsPortable) {
return Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots\dummy.png");
} else {
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png");
}
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png");
case "OutputFilePath":
if (IniConfig.IsPortable) {
string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots");
@ -515,16 +514,6 @@ namespace GreenshotPlugin.Core {
if (WebRequestReadWriteTimeout < 1) {
WebRequestReadWriteTimeout = 100;
}
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC)
if (!Directory.Exists(OutputFilePath))
{
OutputFilePath = GetDefault(nameof(OutputFilePath)) as string;
}
if (!File.Exists(OutputFileAsFullpath))
{
OutputFileAsFullpath = GetDefault(nameof(OutputFileAsFullpath)) as string;
}
}
}
}