2004-07-12 04:16:09 +00:00
|
|
|
/** <title>GormFilePrefsManager</title>
|
|
|
|
|
|
|
|
<abstract>Sets the information about the .gorm file's version.
|
|
|
|
This allows a file to be saved as an older version of the .gorm
|
|
|
|
format so that older releases can still use .gorm files created
|
|
|
|
by people who have the latest GNUstep and Gorm version.</abstract>
|
|
|
|
|
|
|
|
Copyright (C) 2003 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Gregory John Casamento
|
|
|
|
Date: July 2003.
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
2007-11-05 23:44:36 +00:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
2004-07-12 04:16:09 +00:00
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this library;
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* All Rights reserved */
|
|
|
|
|
2019-11-03 01:57:39 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
2004-07-12 04:16:09 +00:00
|
|
|
#include <AppKit/AppKit.h>
|
2019-11-03 01:57:39 +00:00
|
|
|
|
|
|
|
#include <InterfaceBuilder/InterfaceBuilder.h>
|
|
|
|
|
|
|
|
#include <GNUstepBase/GSObjCRuntime.h>
|
2008-12-02 07:54:31 +00:00
|
|
|
#include <GNUstepGUI/GSGormLoading.h>
|
2019-11-03 01:57:39 +00:00
|
|
|
|
2004-07-12 04:16:09 +00:00
|
|
|
#include "GormFilePrefsManager.h"
|
|
|
|
#include "GormFunctions.h"
|
2006-08-01 04:16:34 +00:00
|
|
|
#include "GormDocument.h"
|
2004-07-12 04:16:09 +00:00
|
|
|
|
2013-11-04 15:02:25 +00:00
|
|
|
NSString *formatVersion(NSInteger version)
|
2004-07-12 04:16:09 +00:00
|
|
|
{
|
2013-11-04 15:02:25 +00:00
|
|
|
NSInteger bit16 = 65536;
|
|
|
|
NSInteger bit8 = 256;
|
|
|
|
NSInteger maj = 0;
|
|
|
|
NSInteger min = 0;
|
|
|
|
NSInteger pch = 0;
|
|
|
|
NSInteger v = version;
|
2004-07-12 04:16:09 +00:00
|
|
|
|
|
|
|
// pull the version fromt the number
|
|
|
|
maj = (int)((float)v / (float)bit16);
|
|
|
|
v -= (bit16 * maj);
|
|
|
|
min = (int)((float)v / (float)bit8);
|
|
|
|
v -= (bit8 * min);
|
|
|
|
pch = v;
|
|
|
|
|
2014-05-28 07:02:41 +00:00
|
|
|
return [NSString stringWithFormat: @"%ld.%ld.%ld / %ld",(long)maj,(long)min,(long)pch,(long)version];
|
2004-07-12 04:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@implementation GormFilePrefsManager
|
|
|
|
|
|
|
|
// initializers...
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if((self = [super init]) != nil)
|
|
|
|
{
|
|
|
|
NSBundle *bundle = [NSBundle mainBundle];
|
|
|
|
NSString *path = [bundle pathForResource: @"VersionProfiles" ofType: @"plist"];
|
|
|
|
versionProfiles = RETAIN([[NSString stringWithContentsOfFile: path] propertyList]);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
NSDebugLog(@"Deallocating...");
|
|
|
|
[iwindow performClose: self];
|
|
|
|
RELEASE(iwindow);
|
|
|
|
RELEASE(versionProfiles);
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2004-11-04 02:49:23 +00:00
|
|
|
+ (int) currentVersion
|
|
|
|
{
|
2019-02-07 07:15:01 +00:00
|
|
|
return appVersion(1,2,24);
|
2004-11-04 02:49:23 +00:00
|
|
|
}
|
|
|
|
|
2004-07-12 04:16:09 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2004-11-04 02:49:23 +00:00
|
|
|
version = [GormFilePrefsManager currentVersion];
|
2004-07-12 04:16:09 +00:00
|
|
|
[gormAppVersion setStringValue: formatVersion(version)];
|
|
|
|
ASSIGN(targetVersionName, [[targetVersion selectedItem] title]);
|
|
|
|
ASSIGN(archiveTypeName, [[archiveType selectedItem] title]);
|
|
|
|
[self selectTargetVersion: targetVersion];
|
|
|
|
}
|
|
|
|
|
|
|
|
// set class versions
|
|
|
|
- (void) setClassVersions
|
|
|
|
{
|
|
|
|
NSEnumerator *en = [currentProfile keyEnumerator];
|
|
|
|
id className = nil;
|
|
|
|
|
2004-07-16 01:50:40 +00:00
|
|
|
NSDebugLog(@"set the class versions to the profile selected... %@",targetVersionName);
|
2004-07-12 04:16:09 +00:00
|
|
|
while((className = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
Class cls = NSClassFromString(className);
|
|
|
|
NSDictionary *info = [currentProfile objectForKey: className];
|
2013-11-04 15:02:25 +00:00
|
|
|
NSInteger v = [[info objectForKey: @"version"] intValue];
|
2014-05-28 07:02:41 +00:00
|
|
|
NSDebugLog(@"Setting version %ld for class %@",(long)v,className);
|
2004-07-12 04:16:09 +00:00
|
|
|
[cls setVersion: v];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) restoreClassVersions
|
|
|
|
{
|
|
|
|
NSDictionary *latestVersion = [versionProfiles objectForKey: @"Latest Version"];
|
|
|
|
NSEnumerator *en = [latestVersion keyEnumerator];
|
|
|
|
id className = nil;
|
|
|
|
|
|
|
|
// The "Latest Version" key must always exist.
|
2004-07-16 01:50:40 +00:00
|
|
|
NSDebugLog(@"restore the class versions to the latest version...");
|
2004-07-12 04:16:09 +00:00
|
|
|
while((className = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
Class cls = NSClassFromString(className);
|
|
|
|
NSDictionary *info = [latestVersion objectForKey: className];
|
2013-11-04 15:02:25 +00:00
|
|
|
NSInteger v = [[info objectForKey: @"version"] intValue];
|
2014-05-28 07:02:41 +00:00
|
|
|
NSDebugLog(@"Setting version %ld for class %@",(long)v,className);
|
2004-07-12 04:16:09 +00:00
|
|
|
[cls setVersion: v];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// class profile
|
|
|
|
- (void) loadProfile: (NSString *)profileName
|
|
|
|
{
|
2004-07-16 01:50:40 +00:00
|
|
|
NSDebugLog(@"Loading profile %@",profileName);
|
2004-07-12 04:16:09 +00:00
|
|
|
currentProfile = [versionProfiles objectForKey: targetVersionName];
|
|
|
|
}
|
|
|
|
|
|
|
|
// actions...
|
|
|
|
- (void) showIncompatibilities: (id)sender
|
|
|
|
{
|
|
|
|
[itable reloadData];
|
|
|
|
[iwindow orderFront: self];
|
2004-08-09 21:11:36 +00:00
|
|
|
[iwindow center];
|
2004-07-12 04:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) selectTargetVersion: (id)sender
|
|
|
|
{
|
|
|
|
ASSIGN(targetVersionName, [[sender selectedItem] title]);
|
|
|
|
[self loadProfile: targetVersionName];
|
|
|
|
[itable reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) selectArchiveType: (id)sender
|
|
|
|
{
|
|
|
|
ASSIGN(archiveTypeName, [[sender selectedItem] title]);
|
2004-07-16 01:50:40 +00:00
|
|
|
NSDebugLog(@"Set Archive type... %@",sender);
|
2004-07-12 04:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Loading and saving the file.
|
|
|
|
- (BOOL) saveToFile: (NSString *)path
|
2006-06-05 02:12:00 +00:00
|
|
|
{
|
|
|
|
return [[self data] writeToFile: path atomically: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loading and saving the file.
|
|
|
|
- (NSData *) data
|
2004-07-12 04:16:09 +00:00
|
|
|
{
|
2005-03-31 04:37:40 +00:00
|
|
|
// upon saving, update to the latest.
|
|
|
|
version = [GormFilePrefsManager currentVersion];
|
|
|
|
[gormAppVersion setStringValue: formatVersion(version)];
|
|
|
|
|
2006-06-05 02:12:00 +00:00
|
|
|
// return the data...
|
|
|
|
return [NSArchiver archivedDataWithRootObject: self];
|
2004-07-12 04:16:09 +00:00
|
|
|
}
|
|
|
|
|
2006-08-15 06:18:50 +00:00
|
|
|
- (NSData *) nibDataWithOpenItems: (NSArray *)openItems
|
2006-08-01 04:16:34 +00:00
|
|
|
{
|
|
|
|
NSMutableDictionary *dict =
|
|
|
|
[NSMutableDictionary dictionary];
|
|
|
|
NSRect docLocation =
|
|
|
|
[[(GormDocument *)[(id<IB>)NSApp activeDocument] window] frame];
|
|
|
|
NSRect screenRect = [[NSScreen mainScreen] frame];
|
|
|
|
NSString *stringRect = [NSString stringWithFormat: @"%d %d %d %d %d %d %d %d",
|
2006-08-05 12:48:45 +00:00
|
|
|
(int)docLocation.origin.x, (int)docLocation.origin.y,
|
|
|
|
(int)docLocation.size.width, (int)docLocation.size.height,
|
|
|
|
(int)screenRect.origin.x, (int)screenRect.origin.y,
|
|
|
|
(int)screenRect.size.width, (int)screenRect.size.height];
|
2006-08-01 04:16:34 +00:00
|
|
|
|
|
|
|
// upon saving, update to the latest.
|
|
|
|
version = [GormFilePrefsManager currentVersion];
|
|
|
|
[gormAppVersion setStringValue: formatVersion(version)];
|
|
|
|
|
|
|
|
[dict setObject: stringRect forKey: @"IBDocumentLocation"];
|
|
|
|
[dict setObject: @"437.0" forKey: @"IBFramework Version"];
|
|
|
|
[dict setObject: @"8I127" forKey: @"IBSystem Version"];
|
|
|
|
[dict setObject: [NSNumber numberWithBool: YES]
|
|
|
|
forKey: @"IBUsesTextArchiving"]; // for now.
|
2006-08-15 06:18:50 +00:00
|
|
|
[dict setObject: openItems forKey: @"IBOpenItems"];
|
2006-08-01 04:16:34 +00:00
|
|
|
|
|
|
|
return [NSPropertyListSerialization dataFromPropertyList: dict
|
|
|
|
format: NSPropertyListXMLFormat_v1_0
|
|
|
|
errorDescription: NULL];
|
|
|
|
}
|
|
|
|
|
2005-07-30 08:10:01 +00:00
|
|
|
- (int) versionOfClass: (NSString *)className
|
|
|
|
{
|
2013-11-04 15:02:25 +00:00
|
|
|
NSInteger result = -1;
|
2005-07-30 08:10:01 +00:00
|
|
|
|
|
|
|
NSDictionary *clsProfile = [currentProfile objectForKey: className];
|
|
|
|
if(clsProfile != nil)
|
|
|
|
{
|
|
|
|
NSString *versionString = [clsProfile objectForKey: @"version"];
|
|
|
|
if(versionString != nil)
|
|
|
|
{
|
|
|
|
result = [versionString intValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-07-12 04:16:09 +00:00
|
|
|
- (BOOL) loadFromFile: (NSString *)path
|
2006-06-05 02:12:00 +00:00
|
|
|
{
|
|
|
|
return [self loadFromData: [NSData dataWithContentsOfFile: path]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) loadFromData: (NSData *)data
|
2004-07-12 04:16:09 +00:00
|
|
|
{
|
|
|
|
BOOL result = YES;
|
|
|
|
|
2006-06-05 02:12:00 +00:00
|
|
|
NS_DURING
|
2004-07-12 04:16:09 +00:00
|
|
|
{
|
2012-05-02 03:26:17 +00:00
|
|
|
GormFilePrefsManager *object = (GormFilePrefsManager *)
|
|
|
|
[NSUnarchiver unarchiveObjectWithData: data];
|
2006-06-05 02:12:00 +00:00
|
|
|
[gormAppVersion setStringValue: formatVersion([object version])];
|
|
|
|
version = [object version];
|
|
|
|
[targetVersion selectItemWithTitle: [object targetVersionName]];
|
|
|
|
ASSIGN(targetVersionName,[object targetVersionName]);
|
|
|
|
[archiveType selectItemWithTitle: [object archiveTypeName]];
|
|
|
|
ASSIGN(archiveTypeName, [object archiveTypeName]);
|
|
|
|
[self selectTargetVersion: targetVersion];
|
|
|
|
result = YES;
|
2004-07-12 04:16:09 +00:00
|
|
|
}
|
2006-06-05 02:12:00 +00:00
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
NSLog(@"Problem loading info file: %@",[localException reason]);
|
|
|
|
result = NO;
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER;
|
|
|
|
|
2004-07-12 04:16:09 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// encoding...
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
[coder encodeValueOfObjCType: @encode(int) at: &version];
|
|
|
|
[coder encodeObject: targetVersionName];
|
|
|
|
[coder encodeObject: archiveTypeName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if((self = [super init]) != nil)
|
|
|
|
{
|
|
|
|
[coder decodeValueOfObjCType: @encode(int) at: &version];
|
|
|
|
targetVersionName = [coder decodeObject];
|
|
|
|
archiveTypeName = [coder decodeObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
// accessors
|
|
|
|
- (int) version
|
|
|
|
{
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)targetVersionName
|
|
|
|
{
|
|
|
|
return targetVersionName;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)archiveTypeName
|
|
|
|
{
|
|
|
|
return archiveTypeName;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isLatest
|
|
|
|
{
|
|
|
|
return ([targetVersionName isEqual: @"Latest Version"]);
|
|
|
|
}
|
|
|
|
|
2006-10-04 04:16:47 +00:00
|
|
|
- (void) setFileTypeName: (NSString *)ft
|
|
|
|
{
|
|
|
|
[fileType setStringValue: ft];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) fileTypeName
|
|
|
|
{
|
|
|
|
return [fileType stringValue];
|
|
|
|
}
|
|
|
|
|
2004-07-12 04:16:09 +00:00
|
|
|
// Data Source
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) numberOfRowsInTableView: (NSTableView *)aTableView
|
2004-07-12 04:16:09 +00:00
|
|
|
{
|
|
|
|
return [currentProfile count];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *)aTableView
|
|
|
|
objectValueForTableColumn: (NSTableColumn *)aTableColumn
|
2013-01-30 12:43:27 +00:00
|
|
|
row: (NSInteger)rowIndex
|
2004-07-12 04:16:09 +00:00
|
|
|
{
|
|
|
|
id obj = nil;
|
|
|
|
|
|
|
|
if([[aTableColumn identifier] isEqual: @"item"])
|
|
|
|
{
|
2015-04-17 17:52:51 +00:00
|
|
|
obj = [NSString stringWithFormat: @"#%ld",(long int)rowIndex+1];
|
2004-07-12 04:16:09 +00:00
|
|
|
}
|
|
|
|
else if([[aTableColumn identifier] isEqual: @"description"])
|
|
|
|
{
|
|
|
|
NSArray *keys = [currentProfile allKeys];
|
|
|
|
NSString *key = [keys objectAtIndex: rowIndex];
|
|
|
|
NSDictionary *info = [currentProfile objectForKey: key];
|
|
|
|
obj = [info objectForKey: @"comment"];
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableView: (NSTableView *)aTableView
|
|
|
|
setObjectValue: (id)anObject
|
|
|
|
forTableColumn: (NSTableColumn *)aTableColumn
|
2013-01-30 12:43:27 +00:00
|
|
|
row: (NSInteger)rowIndex
|
2004-07-12 04:16:09 +00:00
|
|
|
{
|
|
|
|
}
|
2006-08-01 04:16:34 +00:00
|
|
|
|
2004-07-12 04:16:09 +00:00
|
|
|
@end
|
|
|
|
|