2001-12-13 18:07:44 +00:00
|
|
|
/*
|
|
|
|
This tool produces a desktop link file for KDE and Gnome out of a GNUstep
|
|
|
|
property list.
|
|
|
|
Copyright (C) 20010 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Fred Kiefer <FredKiefer@gmx.de>
|
|
|
|
Created: December 2001
|
|
|
|
|
|
|
|
This file is part of the GNUstep Project
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSFileManager.h>
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
|
|
|
#include <Foundation/NSString.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char** argv, char **env)
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *pool;
|
|
|
|
NSProcessInfo *procinfo;
|
|
|
|
NSArray *args;
|
|
|
|
NSString *sourceName;
|
|
|
|
NSString *destName;
|
|
|
|
NSMutableString *fileContents;
|
2003-05-14 11:21:51 +00:00
|
|
|
NSDictionary *plist = nil;
|
2001-12-13 18:07:44 +00:00
|
|
|
NSArray *list;
|
|
|
|
NSString *entry;
|
|
|
|
|
|
|
|
#ifdef GS_PASS_ARGUMENTS
|
|
|
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
|
|
|
#endif
|
|
|
|
pool = [NSAutoreleasePool new];
|
|
|
|
procinfo = [NSProcessInfo processInfo];
|
|
|
|
if (procinfo == nil)
|
|
|
|
{
|
|
|
|
NSLog(@"plmerge: unable to get process information!");
|
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2001-12-13 18:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args = [procinfo arguments];
|
|
|
|
|
|
|
|
if ([args count] < 2)
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Usage: %@ input-file [destination-file]\n",
|
|
|
|
[procinfo processName]);
|
2001-12-13 18:07:44 +00:00
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2001-12-13 18:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceName = [args objectAtIndex: 1];
|
|
|
|
if ([args count] > 2)
|
|
|
|
{
|
|
|
|
destName = [args objectAtIndex: 2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Filled in later */
|
|
|
|
destName = nil;
|
|
|
|
}
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
fileContents = [NSString stringWithContentsOfFile: sourceName];
|
|
|
|
plist = [fileContents propertyList];
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - %@\n", sourceName,
|
|
|
|
[localException reason]);
|
2001-12-13 18:07:44 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]])
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr,
|
|
|
|
@"The source property list must contain an NSDictionary.\n");
|
2001-12-13 18:07:44 +00:00
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2001-12-13 18:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fileContents = [NSMutableString stringWithCapacity: 200];
|
2003-12-24 23:26:49 +00:00
|
|
|
[fileContents appendString:
|
|
|
|
@"[Desktop Entry]\nEncoding=UTF-8\nType=Application\n"];
|
|
|
|
[fileContents appendString:
|
|
|
|
@"Version=0.94\nCategories=GNUstep\n"];
|
2001-12-13 18:07:44 +00:00
|
|
|
entry = [plist objectForKey: @"ApplicationName"];
|
|
|
|
if (entry != nil)
|
|
|
|
{
|
|
|
|
[fileContents appendFormat: @"Name=%@\n", entry];
|
|
|
|
if (destName == nil)
|
|
|
|
destName = [entry stringByAppendingString: @".desktop"];
|
|
|
|
}
|
2003-12-24 23:26:49 +00:00
|
|
|
entry = [plist objectForKey: @"ApplicationDescription"];
|
|
|
|
if (entry != nil)
|
|
|
|
{
|
|
|
|
[fileContents appendFormat: @"Comment=%@\n", entry];
|
|
|
|
}
|
2001-12-13 18:07:44 +00:00
|
|
|
entry = [plist objectForKey: @"NSIcon"];
|
|
|
|
if (entry != nil)
|
|
|
|
{
|
|
|
|
if ([[entry pathExtension] isEqualToString: @""])
|
|
|
|
[fileContents appendFormat: @"Icon=%@.tiff\n", entry];
|
|
|
|
else
|
|
|
|
[fileContents appendFormat: @"Icon=%@\n", entry];
|
|
|
|
}
|
|
|
|
entry = [plist objectForKey: @"NSExecutable"];
|
|
|
|
if (entry != nil)
|
|
|
|
{
|
|
|
|
[fileContents appendFormat: @"Exec=openapp %@.app\n", entry];
|
|
|
|
[fileContents appendFormat: @"#TryExec=%@.app\n", entry];
|
2003-12-24 23:26:49 +00:00
|
|
|
[fileContents appendFormat: @"FilePattern=%@.app;%@\n", entry, entry];
|
2001-12-13 18:07:44 +00:00
|
|
|
}
|
|
|
|
|
2001-12-15 13:53:45 +00:00
|
|
|
list = [plist objectForKey: @"NSTypes"];
|
2001-12-13 18:07:44 +00:00
|
|
|
if (list != nil)
|
|
|
|
{
|
2003-01-03 20:14:47 +00:00
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
[fileContents appendString: @"MimeType="];
|
|
|
|
for (i = 0; i < [list count]; i++)
|
|
|
|
{
|
|
|
|
NSArray *types;
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
plist = [list objectAtIndex: i];
|
|
|
|
types = [plist objectForKey: @"NSMIMETypes"];
|
|
|
|
if (types != nil)
|
|
|
|
{
|
|
|
|
for (j = 0; j < [types count]; j++)
|
|
|
|
{
|
|
|
|
entry = [types objectAtIndex: j];
|
|
|
|
[fileContents appendFormat: @"%@;", entry];
|
|
|
|
}
|
|
|
|
}
|
2001-12-15 13:53:45 +00:00
|
|
|
}
|
2003-01-03 20:14:47 +00:00
|
|
|
[fileContents appendString: @"\n"];
|
2001-12-13 18:07:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([[fileContents dataUsingEncoding: NSUTF8StringEncoding]
|
2002-10-11 09:14:14 +00:00
|
|
|
writeToFile: destName atomically: YES] == NO)
|
|
|
|
{
|
|
|
|
GSPrintf(stderr, @"Error writing property list to '%@'\n", destName);
|
|
|
|
}
|
2001-12-13 18:07:44 +00:00
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2001-12-13 18:07:44 +00:00
|
|
|
}
|