Mercurial > hg > audiodb
comparison examples/iAudioDB/AppController.m @ 712:df850498486e
Fixed overwrite handling (shows error if unable to remove existing files).
author | mas01mj |
---|---|
date | Fri, 18 Jun 2010 14:31:58 +0000 |
parents | 362bae792124 |
children | e3087cf8ff14 |
comparison
equal
deleted
inserted
replaced
711:ec23b53ffa14 | 712:df850498486e |
---|---|
102 int numtracks = [maxTracksField intValue]; | 102 int numtracks = [maxTracksField intValue]; |
103 int datasize = ceil((numtracks * vectors * dim * 8.0f) / 1024.0f / 1024.0f); // In MB | 103 int datasize = ceil((numtracks * vectors * dim * 8.0f) / 1024.0f / 1024.0f); // In MB |
104 | 104 |
105 [self reset]; | 105 [self reset]; |
106 | 106 |
107 // Create new db, and set flags. | 107 |
108 db = audiodb_create([[panel filename] cStringUsingEncoding:NSUTF8StringEncoding], datasize, numtracks, dim); | 108 |
109 audiodb_l2norm(db); | |
110 | |
111 // Store useful paths. | 109 // Store useful paths. |
112 dbName = [[[panel URL] relativePath] retain]; | 110 dbName = [[[panel URL] relativePath] retain]; |
113 dbFilename = [[panel filename] retain]; | 111 dbFilename = [[panel filename] retain]; |
114 plistFilename = [[NSString stringWithFormat:@"%@.plist", [dbFilename stringByDeletingPathExtension]] retain]; | 112 plistFilename = [[NSString stringWithFormat:@"%@.plist", [dbFilename stringByDeletingPathExtension]] retain]; |
113 | |
114 // Remove any existing files | |
115 NSFileManager *fileManager = [[NSFileManager alloc] init]; | |
116 | |
117 BOOL overwriteError = NO; | |
118 | |
119 if([fileManager fileExistsAtPath:[panel filename]]) | |
120 { | |
121 if(![fileManager removeItemAtPath:[panel filename] error:NULL]) | |
122 { | |
123 overwriteError = YES; | |
124 } | |
125 } | |
126 | |
127 if(!overwriteError && [fileManager fileExistsAtPath:plistFilename]) | |
128 { | |
129 if(![fileManager removeItemAtPath:plistFilename error:NULL]) | |
130 { | |
131 overwriteError = YES; | |
132 } | |
133 } | |
134 [fileManager release]; | |
135 | |
136 if(overwriteError) | |
137 { | |
138 NSAlert *alert = [[NSAlert alloc] init]; | |
139 [alert addButtonWithTitle:@"OK"]; | |
140 [alert setMessageText:@"Unable to create database."]; | |
141 [alert setInformativeText:@"A database with this name already exists, and could not be overwritten."]; | |
142 [alert setAlertStyle:NSWarningAlertStyle]; | |
143 [alert runModal]; | |
144 [alert release]; | |
145 return; | |
146 } | |
147 | |
148 // Create new db, and set flags. | |
149 db = audiodb_create([[panel filename] cStringUsingEncoding:NSUTF8StringEncoding], datasize, numtracks, dim); | |
150 audiodb_l2norm(db); | |
115 | 151 |
116 // Create the plist file (contains mapping from filename to key). | 152 // Create the plist file (contains mapping from filename to key). |
117 dbState = [[NSMutableDictionary alloc] init]; | 153 dbState = [[NSMutableDictionary alloc] init]; |
118 trackMap = [[NSMutableDictionary alloc] init]; | 154 trackMap = [[NSMutableDictionary alloc] init]; |
119 [dbState setValue:trackMap forKey:@"tracks"]; | 155 [dbState setValue:trackMap forKey:@"tracks"]; |