mirror of
https://github.com/ogoguel/activegs-ios.git
synced 2024-12-27 02:29:21 +00:00
Support multi-disk images for user-provided disk images placed in the Documents directory. Multi disk images are recognized by having disk1 and having a common filename prefix
This commit is contained in:
parent
00a7bf4a5f
commit
953c76e076
@ -61,6 +61,13 @@ void xmltostring(simplexml* _this,MyString& _output)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@interface DiskImageInfo : NSObject
|
||||||
|
@property (strong, nonatomic) NSString *name;
|
||||||
|
@property (nonatomic) NSUInteger slotNumber;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation DiskImageInfo
|
||||||
|
@end
|
||||||
|
|
||||||
static UIImage* defaultImage2GS = nil;
|
static UIImage* defaultImage2GS = nil;
|
||||||
static UIImage* defaultImageII = nil;
|
static UIImage* defaultImageII = nil;
|
||||||
@ -101,101 +108,151 @@ static UIImage* defaultImageII = nil;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)retrieveDocumentList:(MyString&) tempXML withBaseURL:(MyString&) _baseUrl;
|
-(void) createXmlUsingStringRef:(MyString&)tempXML withBaseURLRef:(MyString&)_baseUrl {
|
||||||
{
|
|
||||||
|
tempXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<list version=\"1\">";
|
||||||
tempXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<list version=\"1\">";
|
tempXML += "<source>My 2GS</source>";
|
||||||
tempXML += "<source>My 2GS</source>";
|
|
||||||
|
NSArray *dopaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
||||||
NSArray *dopaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
||||||
NSString *documentsDirectory = [dopaths objectAtIndex:0];
|
NSString *documentsDirectory = [dopaths objectAtIndex:0];
|
||||||
NSFileManager *manager = [NSFileManager defaultManager];
|
NSFileManager *manager = [NSFileManager defaultManager];
|
||||||
// NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
|
// NSArray *fileList = [manager directoryContentsAtPath:documentsDirectory];
|
||||||
NSError* err;
|
NSError* err;
|
||||||
NSArray *fileList = [manager contentsOfDirectoryAtPath:documentsDirectory error:&err];
|
NSArray *fileList = [manager contentsOfDirectoryAtPath:documentsDirectory error:&err];
|
||||||
|
|
||||||
MyString ignoreList;
|
MyString ignoreList;
|
||||||
|
|
||||||
const char* utf8docdir = [documentsDirectory UTF8String];
|
const char* utf8docdir = [documentsDirectory UTF8String];
|
||||||
listPath.Format("%s/LOCAL.ACTIVEGSXML",utf8docdir);
|
listPath.Format("%s/LOCAL.ACTIVEGSXML",utf8docdir);
|
||||||
_baseUrl =listPath;
|
_baseUrl =listPath;
|
||||||
|
|
||||||
CDownload dl(utf8docdir);
|
CDownload dl(utf8docdir);
|
||||||
dl.bNotifyDownloadFailure = true;
|
dl.bNotifyDownloadFailure = true;
|
||||||
|
|
||||||
|
|
||||||
// parse déjà les fichier .activegsxml
|
// parse déjà les fichier .activegsxml
|
||||||
|
|
||||||
for (NSString *s in fileList)
|
for (NSString *s in fileList)
|
||||||
{
|
{
|
||||||
const char* fn = [s UTF8String];
|
const char* fn = [s UTF8String];
|
||||||
const char* ext = getext(fn);
|
const char* ext = getext(fn);
|
||||||
|
|
||||||
if (strcasecmp(ext,"activegsxml"))
|
if (strcasecmp(ext,"activegsxml"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
MyString fullpathname = utf8docdir;
|
MyString fullpathname = utf8docdir;
|
||||||
fullpathname += "/";
|
fullpathname += "/";
|
||||||
fullpathname += fn;
|
fullpathname += fn;
|
||||||
*/
|
*/
|
||||||
MyString path;
|
MyString path;
|
||||||
MyString shortname;
|
MyString shortname;
|
||||||
|
|
||||||
dl.retrieveFile(fn,path,shortname);
|
dl.retrieveFile(fn,path,shortname);
|
||||||
FILE* f= fopen(path.c_str(),"rb");
|
FILE* f= fopen(path.c_str(),"rb");
|
||||||
if (!f) continue;
|
if (!f) continue;
|
||||||
fseek(f,0,SEEK_END);
|
fseek(f,0,SEEK_END);
|
||||||
int si = ftell(f);
|
int si = ftell(f);
|
||||||
|
|
||||||
|
|
||||||
fseek(f,0,SEEK_SET);
|
fseek(f,0,SEEK_SET);
|
||||||
char *buf = new char[si+1];
|
char *buf = new char[si+1];
|
||||||
memset(buf,0,si+1);
|
memset(buf,0,si+1);
|
||||||
fread(buf,1,si,f);
|
fread(buf,1,si,f);
|
||||||
simplexml* p = new simplexml(buf);
|
simplexml* p = new simplexml(buf);
|
||||||
if (!p)
|
if (!p)
|
||||||
{
|
{
|
||||||
delete buf;
|
delete buf;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!strcasecmp(p->key(),"config"))
|
if (!strcasecmp(p->key(),"config"))
|
||||||
{
|
{
|
||||||
MyString temp;
|
MyString temp;
|
||||||
xmltostring(p,temp);
|
xmltostring(p,temp);
|
||||||
printf("%s",temp.c_str());
|
printf("%s",temp.c_str());
|
||||||
tempXML += temp.c_str();
|
tempXML += temp.c_str();
|
||||||
|
|
||||||
// rajoute les images dans une liste blackliste
|
// rajoute les images dans une liste blackliste
|
||||||
for(int i=0;i<p->number_of_children();i++)
|
for(int i=0;i<p->number_of_children();i++)
|
||||||
{
|
{
|
||||||
simplexml* child = p->child(i);
|
simplexml* child = p->child(i);
|
||||||
if (!strcmp(child->key(),"image"))
|
if (!strcmp(child->key(),"image"))
|
||||||
{
|
{
|
||||||
int order;
|
int order;
|
||||||
MyString path;
|
MyString path;
|
||||||
int isLocal = dl.parseFilenameAndMakeAbsolute(child->value(), order, path);
|
int isLocal = dl.parseFilenameAndMakeAbsolute(child->value(), order, path);
|
||||||
if (isLocal)
|
if (isLocal)
|
||||||
{
|
{
|
||||||
ignoreList+="?";
|
ignoreList+="?";
|
||||||
ignoreList+=getfile(path);
|
ignoreList+=getfile(path);
|
||||||
ignoreList+="?";
|
ignoreList+="?";
|
||||||
// printf("ignoring:%s",getfile(path.c_str()));
|
// printf("ignoring:%s",getfile(path.c_str()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete buf;
|
delete buf;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse les autres fichiers
|
// support multi-disk images by checking for the presence of "disk1" and create multiple disk image elements
|
||||||
for (NSString *s in fileList)
|
|
||||||
{
|
// setup multi disk detection
|
||||||
const char* fn = [s UTF8String];
|
NSString *currentMultiDiskPrefix = nil;
|
||||||
const char* ext = getext(fn);
|
NSMutableArray *currentMultiDiskFilenames = [NSMutableArray array];
|
||||||
|
|
||||||
if ( strcasecmp(ext,"zip")
|
// block to write out xml for individual programs
|
||||||
|
void (^generateXmlForDiskImages)(NSArray *) = ^(NSArray *diskImages) {
|
||||||
|
DiskImageInfo *firstImage = [diskImages firstObject];
|
||||||
|
const char* cFilename = [firstImage.name UTF8String];
|
||||||
|
int slot = (int) firstImage.slotNumber;
|
||||||
|
|
||||||
|
tempXML += "<config version=\"2\">";
|
||||||
|
tempXML += "<name>";
|
||||||
|
tempXML += getfilenoext(cFilename);
|
||||||
|
tempXML += "</name>";
|
||||||
|
|
||||||
|
if (slot==6)
|
||||||
|
tempXML += "<format>APPLE 2</format>";
|
||||||
|
else
|
||||||
|
tempXML += "<format>2GS</format>";
|
||||||
|
|
||||||
|
tempXML += "<pic type=\"thumbnail\">";
|
||||||
|
// tempXML += utf8docdir;
|
||||||
|
// tempXML += "/";
|
||||||
|
tempXML += getfilenoext(cFilename);
|
||||||
|
tempXML += ".png</pic>";
|
||||||
|
|
||||||
|
MyString slotstr;
|
||||||
|
slotstr.Format("%d",slot);
|
||||||
|
|
||||||
|
BOOL isIIGSMultiMoreThanTwoDisks = slot != 6 && diskImages.count > 2;
|
||||||
|
|
||||||
|
[diskImages enumerateObjectsUsingBlock:^(DiskImageInfo *diskImage, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||||
|
unsigned long diskIndex = idx + 1;
|
||||||
|
if ( slot == 6 || isIIGSMultiMoreThanTwoDisks ) {
|
||||||
|
// for Apple II disks, assume 1 disk drive
|
||||||
|
// for Apple IIGS that have more than 2 disks, use 1 drive
|
||||||
|
diskIndex = 1;
|
||||||
|
}
|
||||||
|
tempXML += "<image slot=\"";
|
||||||
|
tempXML += slotstr;
|
||||||
|
tempXML += [[NSString stringWithFormat:@"\" disk=\"%lu\">",diskIndex] UTF8String];
|
||||||
|
tempXML += [diskImage.name UTF8String];
|
||||||
|
tempXML += "</image>";
|
||||||
|
}];
|
||||||
|
tempXML += "<bootslot>";
|
||||||
|
tempXML += slotstr;
|
||||||
|
tempXML += "</bootslot>";
|
||||||
|
tempXML += "</config>";
|
||||||
|
};
|
||||||
|
|
||||||
|
for (NSString *s in fileList)
|
||||||
|
{
|
||||||
|
const char* fn = [s UTF8String];
|
||||||
|
const char* ext = getext(fn);
|
||||||
|
|
||||||
|
if ( strcasecmp(ext,"zip")
|
||||||
&& strcasecmp(ext,"2mg")
|
&& strcasecmp(ext,"2mg")
|
||||||
&& strcasecmp(ext,"raw")
|
&& strcasecmp(ext,"raw")
|
||||||
&& strcasecmp(ext,"dsk")
|
&& strcasecmp(ext,"dsk")
|
||||||
@ -203,73 +260,82 @@ static UIImage* defaultImageII = nil;
|
|||||||
&& strcasecmp(ext,"do")
|
&& strcasecmp(ext,"do")
|
||||||
&& strcasecmp(ext,"nib")
|
&& strcasecmp(ext,"nib")
|
||||||
&& strcasecmp(ext,"bin"))
|
&& strcasecmp(ext,"bin"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// si le fichier est dans la liste des blacklistée : ignore
|
// si le fichier est dans la liste des blacklistée : ignore
|
||||||
MyString pat;
|
MyString pat;
|
||||||
pat.Format("?%s?",fn);
|
pat.Format("?%s?",fn);
|
||||||
if (ignoreList.Find(pat)!=-1)
|
if (ignoreList.Find(pat)!=-1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
// check if file exists
|
||||||
MyString fullpathname = utf8docdir;
|
MyString path;
|
||||||
fullpathname += "/";
|
MyString shortname;
|
||||||
fullpathname += fn;
|
dl.retrieveFile(fn,path,shortname);
|
||||||
*/
|
FILE* f= fopen(path.c_str(),"rb");
|
||||||
|
if (!f) continue;
|
||||||
MyString path;
|
|
||||||
MyString shortname;
|
// determine slot based on disk size
|
||||||
// CDownload dl;
|
fseek(f,0,SEEK_END);
|
||||||
// dl.bNotifyDownloadFailure = true;
|
int si = (int) ftell(f);
|
||||||
dl.retrieveFile(fn,path,shortname);
|
int slot;
|
||||||
FILE* f= fopen(path.c_str(),"rb");
|
if (si < 800*1024)
|
||||||
if (!f) continue;
|
slot = 6;
|
||||||
fseek(f,0,SEEK_END);
|
else
|
||||||
int si = ftell(f);
|
if (si < 900*1024)
|
||||||
|
slot = 5;
|
||||||
int slot;
|
else
|
||||||
if (si < 800*1024)
|
slot = 7;
|
||||||
slot = 6;
|
fclose(f);
|
||||||
else
|
|
||||||
if (si < 900*1024)
|
// strip out the spaces in the filename to help in comparison
|
||||||
slot = 5;
|
NSString *comparisonFilename = [[s stringByReplacingOccurrencesOfString:@" " withString:@""] lowercaseString];
|
||||||
else
|
|
||||||
slot = 7;
|
if ( currentMultiDiskPrefix != nil && [comparisonFilename containsString:currentMultiDiskPrefix] ) {
|
||||||
|
// in the middle of multidisk images, add this and continue
|
||||||
tempXML += "<config version=\"2\">";
|
DiskImageInfo *info = [[DiskImageInfo alloc] init];
|
||||||
tempXML += "<name>";
|
info.name = s;
|
||||||
tempXML += getfilenoext(fn);
|
info.slotNumber = slot;
|
||||||
tempXML += "</name>";
|
[currentMultiDiskFilenames addObject:info];
|
||||||
|
continue;
|
||||||
if (slot==6)
|
}
|
||||||
tempXML += "<format>APPLE 2</format>";
|
|
||||||
else
|
// finish up creating the last multidisk images, if necessary
|
||||||
tempXML += "<format>2GS</format>";
|
if ( [currentMultiDiskFilenames count] > 0 ) {
|
||||||
|
generateXmlForDiskImages(currentMultiDiskFilenames);
|
||||||
tempXML += "<pic type=\"thumbnail\">";
|
[currentMultiDiskFilenames removeAllObjects];
|
||||||
// tempXML += utf8docdir;
|
currentMultiDiskPrefix = nil;
|
||||||
// tempXML += "/";
|
}
|
||||||
tempXML += getfilenoext(fn);
|
|
||||||
tempXML += ".png</pic>";
|
// this is a new disk image set
|
||||||
|
// check if multi disk
|
||||||
tempXML += "<image slot=\"";
|
NSRange rangeOfMultiDiskIndicator = [comparisonFilename rangeOfString:@"disk1"];
|
||||||
MyString slotstr;
|
if ( rangeOfMultiDiskIndicator.location != NSNotFound ) {
|
||||||
slotstr.Format("%d",slot);
|
[currentMultiDiskFilenames removeAllObjects];
|
||||||
tempXML += slotstr;
|
DiskImageInfo *info = [[DiskImageInfo alloc] init];
|
||||||
tempXML += "\" disk=\"1\">";
|
info.name = s;
|
||||||
tempXML += fn;
|
info.slotNumber = slot;
|
||||||
tempXML += "</image>";
|
[currentMultiDiskFilenames addObject:info];
|
||||||
tempXML += "<bootslot>";
|
currentMultiDiskPrefix = [[comparisonFilename substringWithRange:NSMakeRange(0, rangeOfMultiDiskIndicator.location)] lowercaseString];
|
||||||
tempXML += slotstr;
|
continue;
|
||||||
tempXML += "</bootslot>";
|
}
|
||||||
tempXML += "</config>";
|
|
||||||
|
// single disk
|
||||||
|
DiskImageInfo *diskImage = [[DiskImageInfo alloc] init];
|
||||||
fclose(f);
|
diskImage.name = s;
|
||||||
|
diskImage.slotNumber = slot;
|
||||||
|
generateXmlForDiskImages(@[diskImage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempXML+="</list>";
|
// deal with any left over multidisk images
|
||||||
printf(tempXML.c_str());
|
if ( [currentMultiDiskFilenames count] > 0 ) {
|
||||||
|
generateXmlForDiskImages(currentMultiDiskFilenames);
|
||||||
|
[currentMultiDiskFilenames removeAllObjects];
|
||||||
|
currentMultiDiskPrefix = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
tempXML+="</list>";
|
||||||
|
printf(tempXML.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
- (simplexml*)addList:(const char*)_listPath
|
- (simplexml*)addList:(const char*)_listPath
|
||||||
@ -293,7 +359,8 @@ static UIImage* defaultImageII = nil;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
MyString baseURL;
|
MyString baseURL;
|
||||||
[self retrieveDocumentList:xmlString withBaseURL:baseURL];
|
[self createXmlUsingStringRef:xmlString withBaseURLRef:baseURL];
|
||||||
|
// [self retrieveDocumentList:xmlString withBaseURL:baseURL];
|
||||||
list.pathName = baseURL;
|
list.pathName = baseURL;
|
||||||
list.processString(xmlString.c_str());
|
list.processString(xmlString.c_str());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user