Skip to content

Commit

Permalink
Second attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
windymilla committed Dec 2, 2023
1 parent de8440f commit 2db8226
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
9 changes: 5 additions & 4 deletions src/lib/Guiguts/Preferences.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ BEGIN {
sub setdefaultpath {
my ( $oldpath, $defaultpath, $forcedefault ) = @_;
my $newpath = '';
if ( -e $defaultpath or $forcedefault ) # If default path exists, consider it for new path
if ( -e $defaultpath or $forcedefault ) # If default path exists (or forced), consider it for new path
{
$newpath = $defaultpath;
} else { # Otherwise check for no-extension version or elsewhere on path
Expand All @@ -43,7 +43,7 @@ sub setdefaultpath {
}
$newpath = $oldpath unless $newpath; # Use oldpath if new path not found

if ( $newpath && -e $newpath ) {
if ( $newpath and ( -e $newpath or $forcedefault ) ) {
my $index = index( $newpath, 'tools' );
$index = index( $newpath, 'scannos' ) if $index < 0;
if ( $index >= 0 ) { # New path is in tools or scannos under the release
Expand All @@ -67,11 +67,12 @@ sub setdefaultpath {
# Either new and old have matching tails, or no suitable old - return relative path tail
return $newtail;
} else { # Not under tools subfolder - use old if it exists, otherwise use new default
return $oldpath if $oldpath && -e $oldpath;
print "PATHS1\n$oldpath\n$newpath\n\n" if $forcedefault;
return $oldpath if $oldpath && -e $oldpath;
return $newpath;
}
} else {
print "PATHS\n$oldpath\n$defaultpath\n\n";
print "PATHS2\n$oldpath\n$defaultpath\n\n" if $forcedefault;
return ( $oldpath ? $oldpath : $defaultpath ); # If all else fails return old path, or if empty, the default path
}
}
Expand Down
32 changes: 18 additions & 14 deletions src/lib/Guiguts/Utilities.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1256,29 +1256,33 @@ sub initialize {
# If XnView or Aspell are installed under "Program Files (x86)",
# set that as the default, otherwise use "Program Files"
# Suitable for Windows installation locations
my $trypath = ::catfile( '\Program Files (x86)', 'XnView', 'xnview.exe' );
if ( -e $trypath ) {
$::globalviewerpath = ::setdefaultpath( $::globalviewerpath, $trypath );
} else {
$::globalviewerpath = ::setdefaultpath( $::globalviewerpath,
::catfile( '\Program Files', 'XnView', 'xnview.exe' ) );
}
$trypath = ::catfile( '\Program Files (x86)', 'Aspell', 'bin', 'aspell.exe' );
if ( -e $trypath ) {
$::globalspellpath = ::setdefaultpath( $::globalspellpath, $trypath );
} else {
$::globalspellpath = ::setdefaultpath( $::globalspellpath,
::catfile( '\Program Files', 'Aspell', 'bin', 'aspell.exe' ) );
if ($::OS_WIN) {
my $trypath = ::catfile( '\Program Files (x86)', 'XnView', 'xnview.exe' );
if ( -e $trypath ) {
$::globalviewerpath = ::setdefaultpath( $::globalviewerpath, $trypath );
} else {
$::globalviewerpath = ::setdefaultpath( $::globalviewerpath,
::catfile( '\Program Files', 'XnView', 'xnview.exe' ) );
}
$trypath = ::catfile( '\Program Files (x86)', 'Aspell', 'bin', 'aspell.exe' );
if ( -e $trypath ) {
$::globalspellpath = ::setdefaultpath( $::globalspellpath, $trypath );
} else {
$::globalspellpath = ::setdefaultpath( $::globalspellpath,
::catfile( '\Program Files', 'Aspell', 'bin', 'aspell.exe' ) );
}
}

# Override to more likely default locations for Mac
if ($::OS_MAC) {

# Force consideration of default Mac Preview command even though it doesn't "exist" as file path
print "PRE: $::globalviewerpath";
$::globalviewerpath = ::setdefaultpath( $::globalviewerpath, 'open -g -a Preview', 1 );
print "POST: $::globalviewerpath";

# M1 and Intel-based Macs have some tools installed in different locations
$trypath = ::catfile( '/opt', 'homebrew', 'bin', 'aspell' );
my $trypath = ::catfile( '/opt', 'homebrew', 'bin', 'aspell' );
if ( -e $trypath ) {
$::globalspellpath = ::setdefaultpath( $::globalspellpath, $trypath );
} else {
Expand Down

0 comments on commit 2db8226

Please sign in to comment.