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}"; pattern = "greenshot ${capturetime}";
} }
string filename = FilenameHelper.GetFilenameFromPattern(pattern, CoreConfig.OutputFileFormat, captureDetails); 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); string filepath = FilenameHelper.FillVariables(CoreConfig.OutputFilePath, false);
try { try {
fullPath = Path.Combine(filepath, filename); fullPath = Path.Combine(filepath, filename);

View file

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

View file

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

View file

@ -342,9 +342,8 @@ namespace GreenshotPlugin.Core {
case "OutputFileAsFullpath": case "OutputFileAsFullpath":
if (IniConfig.IsPortable) { if (IniConfig.IsPortable) {
return Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots\dummy.png"); 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": case "OutputFilePath":
if (IniConfig.IsPortable) { if (IniConfig.IsPortable) {
string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots"); string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots");
@ -515,16 +514,6 @@ namespace GreenshotPlugin.Core {
if (WebRequestReadWriteTimeout < 1) { if (WebRequestReadWriteTimeout < 1) {
WebRequestReadWriteTimeout = 100; 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;
}
} }
} }
} }