Fix for opening files with relative paths.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@17964 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2003-10-24 09:29:43 +00:00
parent 33e7efecea
commit ac16f41d6f
3 changed files with 39 additions and 13 deletions

View file

@ -1,3 +1,11 @@
2003-10-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSWorkspace.m: Change a few uses of '/' in stgrings to
use stringByAppendingPatchComponent:
* Tools/gopen.m: Fix to pass the full path of the file to the
app being used to open it, so relative paths in the arguments
work properly.
2003-10-21 Bjorn Giesler <bjoern@giesler.de> 2003-10-21 Bjorn Giesler <bjoern@giesler.de>
* Source/GSServicesManager.m: Fix NSPerformService() to work for * Source/GSServicesManager.m: Fix NSPerformService() to work for

View file

@ -1105,7 +1105,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
} }
/** /**
* <p>Launches the specified application (unless it is alreeady running).<br /> * <p>Launches the specified application (unless it is already running).<br />
* If the autolaunch flag is yes, sets the autolaunch user default for the * If the autolaunch flag is yes, sets the autolaunch user default for the
* newly launched application, so that applications which understand the * newly launched application, so that applications which understand the
* concept of being autolaunched at system startup time can modify their * concept of being autolaunched at system startup time can modify their
@ -1528,7 +1528,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
} }
else else
{ {
path = [path stringByAppendingFormat: @"/%@", file]; path = [path stringByAppendingPathComponent: file];
} }
} }
@ -1644,7 +1644,8 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
*/ */
if (iconPath == nil) if (iconPath == nil)
{ {
iconPath = [[bundle bundlePath] stringByAppendingPathComponent: file]; iconPath = [[bundle bundlePath]
stringByAppendingPathComponent: file];
} }
file = iconPath; file = iconPath;
} }
@ -1712,7 +1713,7 @@ inFileViewerRootedAtPath: (NSString*)rootFullpath
absolute = [[NSURL fileURLWithPath: [file stringByStandardizingPath]] absolute = [[NSURL fileURLWithPath: [file stringByStandardizingPath]]
absoluteString]; absoluteString];
// This compensates for a bug we have in NSURL, that is there to have // This compensates for a feature we have in NSURL, that is there to have
// MacOSX compatibility. // MacOSX compatibility.
if ([absolute hasPrefix: @"file://localhost/"]) if ([absolute hasPrefix: @"file://localhost/"])
{ {

View file

@ -35,6 +35,17 @@
#include <AppKit/NSApplication.h> #include <AppKit/NSApplication.h>
#include <AppKit/NSWorkspace.h> #include <AppKit/NSWorkspace.h>
static NSString*
absolutePath(NSFileManager *fm, NSString *path)
{
path = [path stringByStandardizingPath];
if ([path isAbsolutePath] == NO)
{
path = [[fm currentDirectoryPath] stringByAppendingPathComponent: path];
}
return path;
}
int int
main(int argc, char** argv, char **env_c) main(int argc, char** argv, char **env_c)
{ {
@ -79,12 +90,14 @@ main(int argc, char** argv, char **env_c)
if (filetoopen) if (filetoopen)
{ {
filetoopen = absolutePath(fm, filetoopen);
[workspace openFile: filetoopen [workspace openFile: filetoopen
withApplication: application]; withApplication: application];
} }
if (filetoprint) if (filetoprint)
{ {
filetoprint = absolutePath(fm, filetoprint);
puts("Not implemented"); puts("Not implemented");
} }
@ -95,11 +108,11 @@ main(int argc, char** argv, char **env_c)
if (argc == 1) if (argc == 1)
{ {
NSFileHandle *fh = [NSFileHandle fileHandleWithStandardInput]; NSFileHandle *fh = [NSFileHandle fileHandleWithStandardInput];
NSData *data = [fh readDataToEndOfFile]; NSData *data = [fh readDataToEndOfFile];
NSString *tempFile = [NSTemporaryDirectory() NSString *tempFile = [NSTemporaryDirectory()
stringByAppendingPathComponent: @"openfiletmp"]; stringByAppendingPathComponent: @"openfiletmp"];
NSNumber *processId = [NSNumber numberWithInt: NSNumber *processId = [NSNumber numberWithInt:
[[NSProcessInfo processInfo] processIdentifier]]; [[NSProcessInfo processInfo] processIdentifier]];
tempFile = [tempFile stringByAppendingString: [processId stringValue]]; tempFile = [tempFile stringByAppendingString: [processId stringValue]];
@ -140,6 +153,10 @@ main(int argc, char** argv, char **env_c)
BOOL isDir = NO, exists = NO; BOOL isDir = NO, exists = NO;
exists = [fm fileExistsAtPath: arg isDirectory: &isDir]; exists = [fm fileExistsAtPath: arg isDirectory: &isDir];
if (exists == YES)
{
arg = absolutePath(fm, arg);
}
if (exists && !isDir && [fm isExecutableFileAtPath: arg]) if (exists && !isDir && [fm isExecutableFileAtPath: arg])
{ {
[workspace openFile: arg withApplication: terminal]; [workspace openFile: arg withApplication: terminal];
@ -147,9 +164,9 @@ main(int argc, char** argv, char **env_c)
else // no argument specified else // no argument specified
{ {
// First check to see if it's an application // First check to see if it's an application
if ([ext isEqualToString: @"app"] || if ([ext isEqualToString: @"app"]
[ext isEqualToString: @"debug"] || || [ext isEqualToString: @"debug"]
[ext isEqualToString: @"profile"]) || [ext isEqualToString: @"profile"])
{ {
NSString *appName = NSString *appName =
[[arg lastPathComponent] stringByDeletingPathExtension]; [[arg lastPathComponent] stringByDeletingPathExtension];
@ -172,7 +189,7 @@ main(int argc, char** argv, char **env_c)
else else
{ {
if (![workspace openFile: arg if (![workspace openFile: arg
withApplication: application]) withApplication: application])
{ {
// no recognized extension, // no recognized extension,
// run application indicated by environment var. // run application indicated by environment var.