# HG changeset patch # User koda # Date 1289615140 -3600 # Node ID 82f1f1d819c07517cfd116eb339aad4d89e09dad # Parent 7dbdc862097ccdd87a77212beca7224c4ed5be37 don't list too big maps for certain devices diff -r 7dbdc862097c -r 82f1f1d819c0 project_files/HedgewarsMobile/Classes/CommodityFunctions.h --- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Sat Nov 13 01:24:39 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.h Sat Nov 13 03:25:40 2010 +0100 @@ -70,3 +70,5 @@ NSArray *getAvailableColors (void); UILabel *createBlueLabel (NSString *title, CGRect frame); UILabel *createLabelWithParams (NSString *title, CGRect frame, CGFloat borderWidth, UIColor *borderColor, UIColor *backgroundColor); + +CGSize PSPNGSizeFromMetaData (NSString *aFileName); diff -r 7dbdc862097c -r 82f1f1d819c0 project_files/HedgewarsMobile/Classes/CommodityFunctions.m --- a/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Sat Nov 13 01:24:39 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/CommodityFunctions.m Sat Nov 13 03:25:40 2010 +0100 @@ -142,3 +142,47 @@ return theLabel; } + +// this routine checks for the PNG size without loading it in memory +// https://github.com/steipete/PSFramework/blob/master/PSFramework%20Version%200.3/PhotoshopFramework/PSMetaDataFunctions.m +CGSize PSPNGSizeFromMetaData (NSString *aFileName) { + // File Name to C String. + const char *fileName = [aFileName UTF8String]; + // source file + FILE *infile = fopen(fileName, "rb"); + if (infile == NULL) { + DLog(@"Can't open the file: %@", aFileName); + return CGSizeZero; + } + + // Bytes Buffer. + unsigned char buffer[30]; + // Grab Only First Bytes. + fread(buffer, 1, 30, infile); + // Close File. + fclose(infile); + + // PNG Signature. + unsigned char png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; + + // Compare File signature. + if ((int)(memcmp(&buffer[0], &png_signature[0], 8))) { + DLog(@"The file (%@) is not a PNG file", aFileName); + return CGSizeZero; + } + + // Calc Sizes. Isolate only four bytes of each size (width, height). + int width[4]; + int height[4]; + for (int d = 16; d < (16 + 4); d++) { + width[d-16] = buffer[d]; + height[d-16] = buffer[d+4]; + } + + // Convert bytes to Long (Integer) + long resultWidth = (width[0] << (int)24) | (width[1] << (int)16) | (width[2] << (int)8) | width[3]; + long resultHeight = (height[0] << (int)24) | (height[1] << (int)16) | (height[2] << (int)8) | height[3]; + + // Return Size. + return CGSizeMake(resultWidth,resultHeight); +} diff -r 7dbdc862097c -r 82f1f1d819c0 project_files/HedgewarsMobile/Classes/MapConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m Sat Nov 13 01:24:39 2010 +0100 +++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m Sat Nov 13 03:25:40 2010 +0100 @@ -350,19 +350,6 @@ self.staticMapCommand = staticmap; self.missionCommand = mission; - // nice animation for updating the table when appropriate (on iphone) - /* - if (IS_IPAD() == NO) - if (((oldPage == 0 || oldPage == 2) && (newPage == 1 || newPage == 3)) || - ((oldPage == 1 || oldPage == 3) && (newPage == 0 || newPage == 2)) || - ((oldPage == 1 && newPage == 3) || (oldPage == 3 || newPage == 1))) { - self.tableView.frame = CGRectMake(480, 0, 185, 276); - [UIView beginAnimations:@"moving in table" context:NULL]; - self.tableView.frame = CGRectMake(295, 0, 185, 276); - [UIView commitAnimations]; - } - */ - [self.tableView reloadData]; [self updatePreview]; oldPage = newPage; @@ -385,13 +372,36 @@ [string release]; // remove a trailing "" element [themeArray removeLastObject]; - NSArray *mapArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; - NSArray *missionArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL]; + NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; + NSMutableArray *mapArray = [[NSMutableArray alloc] init]; + for (NSString *str in mapArrayFull) { + CGSize imgSize = PSPNGSizeFromMetaData([MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]); + //DLog(@"%@ %f %f", str, imgSize.width, imgSize.height); + if (IS_NOT_POWERFUL() && imgSize.height > 1024.0f) + continue; + if (IS_IPAD() && imgSize.height > 1280.0f) + continue; + [mapArray addObject:str]; + } + NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL]; + NSMutableArray *missionArray = [[NSMutableArray alloc] init]; + for (NSString *str in missionArrayFull) { + CGSize imgSize = PSPNGSizeFromMetaData([MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]); + //DLog(@"%@ %f %f", str, imgSize.width, imgSize.height); + if (IS_NOT_POWERFUL() && imgSize.height > 1024.0f) + continue; + if (IS_IPAD() && imgSize.height > 1280.0f) + continue; + [missionArray addObject:str]; + } NSArray *array = [[NSArray alloc] initWithObjects:themeArray,mapArray,themeArray,missionArray,nil]; + [missionArray release]; + [themeArray release]; + [mapArray release]; + self.dataSourceArray = array; [array release]; - [themeArray release]; } -(void) viewDidLoad { @@ -469,11 +479,9 @@ -(void) didReceiveMemoryWarning { self.dataSourceArray = nil; - self.previewButton = nil; self.tableView = nil; self.maxLabel = nil; self.sizeLabel = nil; - self.segmentedControl = nil; self.slider = nil; MSG_MEMCLEAN();