source: AE/Installer/trunk/source/subs.cpp@ 308

Last change on this file since 308 was 308, checked in by iritscen, 16 years ago

Fixed Mac compat., added globalization (not done).

File size: 21.1 KB
Line 
1/*
2 AE/Mod Installer
3 v1.0
4 by Gumby and Iritscen
5*/
6
7#define DEBUG
8
9#include <string>
10#include <iostream>
11#include <cctype>
12#include <vector>
13#include <fstream>
14#include <errno.h>
15#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
16#include "methods.h"
17
18#ifdef WIN32
19 #include <windows.h>
20#else // assume we're on Mac
21 #include <stdlib.h>
22 #include <dirent.h>
23#endif
24
25#ifdef WIN32
26 const string strOniSplit = "Onisplit.exe";
27 const string strImportOption = "-import:nosep";
28 const char* strClsCmd = "cls";
29 const char* strPauseCmd = "PAUSE";
30#else // set up Mac equivalents since we're in Mac OS
31 const string strOniSplit = "mono Onisplit.exe";
32 const string strImportOption = "-import:sep";
33 const char* strClsCmd = "clear";
34 const char* strPauseCmd = "read -n 1 -p \"Press any key to continue\"";
35#endif
36
37using namespace boost::filesystem;
38using namespace std;
39
40const string strInstallerVersion = "1.0";
41const bool SPLIT = 1;
42const bool NOT_SPLIT = 0;
43bool splitInstances = SPLIT;
44
45int main(void)
46{
47 // SetConsoleTitle("AE Installer"); windows junk, convert to SDL
48 // system("color 0A");
49
50 cout << "\nWelcome to the AE installer!\n";
51 cout << "\nWhat would you like to do?\n";
52
53 return mainMenu();
54}
55
56int mainMenu(void)
57{
58 char choice = '0';
59 bool exit = false;
60 int err = 0;
61
62 do
63 {
64 cout << "\n1. Globalize data\n";
65 cout << "2. Install new packages\n";
66 cout << "3. Uninstall packages\n";
67 cout << "4. See what is installed\n";
68 cout << "5. About AE\n";
69 cout << "6. Quit\n\n";
70
71 choice = cin.get();
72 cin.ignore(128, '\n');
73 switch(choice)
74 {
75 case '1':
76 err = globalizeData();
77 break;
78 case '2':
79 err = installPackages();
80 break;
81 case '3':
82 err = uninstallPackages();
83 break;
84 case '4':
85 err = listInstalledPackages();
86 break;
87 case '5':
88 err = printInstallerInfo();
89 break;
90 case '6':
91 exit = true;
92 break;
93 default:
94 cout << "Please choose one of the above numbers, and press Enter.\n\n";
95 }
96 if (err) // if something fatal happened
97 exit = true;
98 } while(!exit);
99
100 return err;
101}
102
103int globalizeData(void)
104{
105 int err = 0;
106 int levels[15] = {0, 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13, 14, 18, 19}; // the levels Oni has
107 char choice = 0;
108
109 //SetCurrentDirectory("C:/Program Files/Oni/edition/install");
110 char levelnum[3];
111 path Characters = "../GameDataFolder/level0_Characters";
112 path Particles = "../GameDataFolder/level0_Particles";
113 path Archive = "../GameDataFolder/Archive";
114 path Textures = "../GameDataFolder/level0_Textures";
115 path Sounds = "../GameDataFolder/level0_Sounds";
116 path Animations = "../GameDataFolder/level0_Animations";
117 path TRAC = Animations / "level0_TRAC";
118 path TRAM = Animations / "level0_TRAM";
119
120 if (exists("../GameDataFolder/"))
121 {
122 cout << "\nIt looks like you've already globalized Oni's data.\nDo you want to re-globalize?\n(This will erase existing mods installed to the AE's game data.)"
123 << "\n1. Re-globalize"
124 << "\n2. Return to main menu\n";
125 choice = cin.get();
126 cin.ignore(128, '\n');
127 if (choice == '1')
128 remove_all("../GameDataFolder"); // remove AE GDF
129 if (choice == '2')
130 return 0;
131 }
132
133 create_directory( "../GameDataFolder/" );
134 create_directory( "packages" );
135 create_directory( "packages/VanillaDats" );
136 create_directory( "packages/VanillaDats/level0_Final/" );
137 create_directory( Characters );
138 create_directory( Particles );
139 create_directory( Archive );
140 create_directory( Textures );
141 create_directory( Sounds );
142 create_directory( Animations );
143 create_directory( TRAC );
144 create_directory( TRAM );
145
146 for(int i = 0; i < 15; i++)
147 {
148 sprintf(levelnum,"%d",levels[i]); // int to char array
149 exists("../../GameDataFolder/level" + (string)levelnum + "_Final");
150 system((strOniSplit + " -export ../GameDataFolder/level" + (string)levelnum + "_Final ../../GameDataFolder/level" + (string)levelnum + "_Final.dat").c_str());
151
152 create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final" ); //remember to cast your arrays as strings :)
153 create_directory( "packages/VanillaDats/level" + (string)levelnum + "_Final/level" + (string)levelnum + "_Final" );
154
155 directory_iterator end_iter;
156 for ( directory_iterator dir_itr( "../GameDataFolder/level" + (string)levelnum + "_Final" ); dir_itr != end_iter; ++dir_itr )
157 {
158 //cout << dir_itr->path().filename();
159 if ( is_regular_file( dir_itr->status() ) )
160 {
161
162 if ( dir_itr->path().filename().substr(0,8) == "TXMPfail" ||
163 dir_itr->path().filename().substr(0,9) == "TXMPlevel" ||
164 ( dir_itr->path().filename().substr(0,4) == "TXMP" && dir_itr->path().filename().find("intro")!=string::npos) ||
165 dir_itr->path().filename().substr(0,4) == "TXMB" ||
166 dir_itr->path().filename() == "M3GMpowerup_lsi.oni" ||
167 dir_itr->path().filename() == "TXMPlsi_icon.oni" ||
168 ( dir_itr->path().filename().substr(0,4) == "TXMB" && dir_itr->path().filename().find("splash_screen.oni")!=string::npos) )
169 {
170 cout <<dir_itr->path().filename() << "\n";
171 create_directory( dir_itr->path().parent_path() / "NoGlobal");
172 if(!exists( dir_itr->path().parent_path() / "NoGlobal" / dir_itr->filename())) rename(dir_itr->path(), dir_itr->path().parent_path() / "NoGlobal" /
173 dir_itr->filename());
174 else remove(dir_itr->path());
175 }
176 else if (dir_itr->path().filename().substr(0,4) == "TRAC") {
177 cout <<dir_itr->path().filename() << "\n";
178 if(!exists( TRAC / dir_itr->filename())) rename(dir_itr->path(), TRAC / dir_itr->filename());
179 else remove(dir_itr->path());
180 }
181 else if (dir_itr->path().filename().substr(0,4) == "TRAM") {
182 cout <<dir_itr->path().filename() << "\n";
183 if(!exists( TRAM / dir_itr->filename())) rename(dir_itr->path(), TRAM / dir_itr->filename());
184 else remove(dir_itr->path());
185 }
186 else if (dir_itr->path().filename().substr(0,4) == "ONSK" ||
187 dir_itr->path().filename().substr(0,4) == "TXMP") {
188 cout <<dir_itr->path().filename() << "\n";\
189 create_directory( dir_itr->path().parent_path() / "TexFix");
190 if(!exists( Textures / dir_itr->filename())) rename(dir_itr->path(), Textures / dir_itr->filename());
191 //rename(dir_itr->path(), dir_itr->path().parent_path() / "TexFix" / dir_itr->filename());
192 }
193 else if (dir_itr->path().filename().substr(0,4) == "ONCC"
194 || dir_itr->path().filename().substr(0,4) == "TRBS"
195 || dir_itr->path().filename().substr(0,4) == "TRMA"
196 || dir_itr->path().filename().substr(0,4) == "TRSC"
197 || dir_itr->path().filename().substr(0,4) == "TRAS") {
198 cout <<dir_itr->path().filename() << "\n";
199 if(!exists( Characters / dir_itr->filename())) rename(dir_itr->path(), Characters / dir_itr->filename());
200 else remove(dir_itr->path());
201 }
202 else if (dir_itr->path().filename().substr(0,4) == "OSBD"
203 || dir_itr->path().filename().substr(0,4) == "SNDD") {
204 cout << dir_itr->path().filename() << "\n";
205 if(!exists( Sounds / dir_itr->filename())) rename(dir_itr->path(), Sounds / dir_itr->filename());
206 else remove(dir_itr->path());
207 }
208 else if (dir_itr->path().filename().substr(0,5) == "BINA3"
209 || dir_itr->path().filename().substr(0,10) == "M3GMdebris"
210 || dir_itr->path().filename() == "M3GMtoxic_bubble.oni"
211 || dir_itr->path().filename().substr(0,8) == "M3GMelec"
212 || dir_itr->path().filename().substr(0,7) == "M3GMrat"
213 || dir_itr->path().filename().substr(0,7) == "M3GMjet"
214 || dir_itr->path().filename().substr(0,9) == "M3GMbomb_"
215 || dir_itr->path().filename() == "M3GMbarab_swave.oni"
216 || dir_itr->path().filename() == "M3GMbloodyfoot.oni"
217 ){
218 cout <<dir_itr->path().filename() << "\n";
219 if(!exists( Particles / dir_itr->filename())) rename(dir_itr->path(), Particles / dir_itr->filename());
220 else remove(dir_itr->path());
221 }
222 else if (dir_itr->path().filename().substr(0,4) == "AGDB"
223 || dir_itr->path().filename().substr(0,4) == "TRCM") {
224 cout <<dir_itr->path().filename() << "\n";
225
226 if(!exists( Archive / dir_itr->filename())) rename(dir_itr->path(), Archive / dir_itr->filename());
227 else remove(dir_itr->path());
228 }
229 }
230
231
232 }
233 system( (strOniSplit + " -move:delete " + Textures.string() + " ../GameDataFolder/level" + (string)levelnum + "_Final/TXMP*.oni").c_str());
234
235 }
236
237 for (int i = 0; i < 15; i++)
238 {
239 sprintf(levelnum,"%d",levels[i]);
240 system( (strOniSplit + " " + strImportOption + " ../GameDataFolder/level" + levelnum + "_Final packages/VanillaDats/level" + levelnum + "_Final/level"
241 + levelnum + "_Final/level" + levelnum + "_Final.oni").c_str());
242 }
243 path VanillaCharacters = "packages/VanillaDats/level0_Final/level0_Characters/level0_Characters.oni";
244 path VanillaParticles = "packages/VanillaDats/level0_Final/level0_Particles/level0_Particles.oni";
245 path VanillaTextures = "packages/VanillaDats/level0_Final/level0_Textures/level0_Textures.oni";
246 path VanillaSounds = "packages/VanillaDats/level0_Final/level0_Sounds/level0_Sounds.oni";
247 path VanillaAnimations = "packages/VanillaDats/level0_Final/level0_Animations/level0_Animations.oni";
248 path VanillaTRAC = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAC.oni";
249 path VanillaTRAM = "packages/VanillaDats/level0_Final/level0_Animations/level0_TRAM.oni";
250 create_directory( VanillaCharacters.parent_path() );
251 create_directory( VanillaParticles.parent_path() );
252 create_directory( VanillaTextures.parent_path() );
253 create_directory( VanillaSounds.parent_path() );
254 create_directory( VanillaAnimations.remove_filename() );
255 system((strOniSplit + " " + strImportOption + " " + Characters.string() + " " + VanillaCharacters.string()).c_str());
256 system((strOniSplit + " " + strImportOption + " " + Particles.string() + " " + VanillaParticles.string()).c_str());
257 system((strOniSplit + " " + strImportOption + " " + Textures.string() + " " + VanillaTextures.string()).c_str());
258 //system((strOniSplit + " " + strImportOption + (string)" " + Animations.string() + (string)" " + VanillaAnimations.string()).c_str());
259 system((strOniSplit + " " + strImportOption + " " + TRAC.string() + " " + VanillaTRAC.string()).c_str());
260 system((strOniSplit + " " + strImportOption + " " + Sounds.string() + " " + VanillaSounds.string()).c_str());
261 system((strOniSplit + " " + strImportOption + " " + TRAM.string() + " " + VanillaTRAM.string()).c_str());
262
263 create_directory("../GameDataFolder/IGMD");
264 copy_file("packages/VanillaBSL", "../GameDataFolder/IGMD");
265
266 return err;
267}
268
269int installPackages(void)
270{
271 int err = 0;
272 ModPackage package;
273 vector<string> installed_packages;
274 vector<ModPackage> packages;
275 vector<ModPackage>::iterator iter;
276 vector<string> installString;
277
278 iter = packages.begin();
279 packages = getPackages();
280 vector<string> installedMods = getInstallString();
281
282 if (packages.empty())
283 {
284 cout << "Error: You have no packages!\n";
285 return 0;
286 }
287
288 cout << "Detecting installed packages...\n";
289
290 int index = 1;
291 char choice = '0';
292
293 for (vector<ModPackage>::iterator package_iter = packages.begin(); package_iter != packages.end(); ++package_iter)
294 {
295 if (!binary_search(installedMods.begin(), installedMods.end(), package_iter->modStringName))
296 { //package_iter->isInstalled :< I forgot about this...
297 //cout << index << " ";
298 system(strClsCmd);
299 //cout << (*package_iter).name << "\n";
300 for (int character = 1; character <= (*package_iter).name.length() - 1; character++) cout << char(196); //does extended ASCII work in UNIX?
301 cout << "\n"
302 << (*package_iter).readme << "\n\n"
303 << "Please enter a number choice\n"
304 << " 1. Install\n"
305 << " 2. Don't Install\n"
306 << "";
307 index++;
308 choice = 0;
309
310 do
311 {
312 choice = cin.get();
313 cin.ignore(1280, '\n');
314 } while(choice == 0);
315
316 if (choice == '1')
317 {
318 cout << "\nInstalling...\n\n";
319 if (package_iter->hasOnis || (package_iter->hasDeltas /*(*package_iter).isUnpacked */ ))
320 {
321 installedMods.push_back(package_iter->modStringName);
322 system(strPauseCmd);
323 }
324 }
325 }
326 }
327 if (index == 1)
328 {
329 cout << "Error: All packages are already installed\n";
330 return 0;
331 }
332
333 sort(installedMods.begin(), installedMods.end());
334 //system(Onisplit.c_str());
335 recompileAll(installedMods);
336 system(strPauseCmd);
337
338 return err;
339}
340
341int uninstallPackages(void)
342{
343 cout << "\nThis feature not yet implemented.\n\n";
344
345 return 0;
346}
347
348int listInstalledPackages(void)
349{
350 cout << "\nThis feature not yet implemented.\n\n";
351
352 return 0;
353}
354
355int printInstallerInfo(void)
356{
357 cout << "\nAE/Mod Installer\n";
358 cout << "version " << strInstallerVersion << "\n";
359 cout << "by Gumby & Iritscen\n";
360 cout << "see http://oni.bungie.org/community/forums for more info\n\n";
361
362 return 0;
363}
364
365vector<ModPackage> getPackages(void)
366{
367 vector<ModPackage> packages;
368 packages.reserve(65536); // come on, we shouldn't need this much space...right?!
369 fstream file;
370 string filename = "\0";
371 string MODINFO_CFG = "Mod_Info.cfg";
372
373 try
374 {
375 directory_iterator end_iter;
376 for (directory_iterator dir_itr("./packages"); dir_itr != end_iter; ++dir_itr)
377 {
378 file.open((dir_itr->path().string() + "/" + MODINFO_CFG).c_str());
379 //cout << filename << "\n";
380
381 if(!file.fail())
382 {
383 cout << dir_itr->path().string() + MODINFO_CFG;
384 //would prefer to push a pointer to a package, but this will do for now
385 packages.push_back(fileToModPackage(file));
386 }
387 file.close();
388 file.clear();
389 }
390 }
391 catch (const std::exception & ex)
392 {
393 cout << "Warning, something odd happened!\n";
394 }
395
396 return packages;
397}
398
399ModPackage fileToModPackage(fstream &file)
400{
401 /*
402 This converts a file to a ModPackage struct.
403
404 A few notes...
405 "iter" is the current word we are on. I should have named it "token" or something, but I don't have multiple iterators, so its ok.
406 I refer to (*iter) at the beginning of each if statement block. I could probably store it as a variable, but I'm pretty sure that dereferencing a pointer\iterator isn't much
407 slower than reading a variable.
408 */
409 ModPackage package;
410 string line;
411 static string NameOfMod = "NameOfMod"; //used for comparing to the current token...
412 //I could have done it in reverse (*iter).compare("ModString") or
413 static string ARROW = "->"; //did something like "ModString".compare(*iter), and it would have been
414 static string ModString = "ModString"; //functionably the same.
415 static string HasOnis = "HasOnis";
416 static string HasDeltas = "HasDeltas";
417 static string HasBSL = "HasBSL";
418 static string HasDats = "HasDats";
419 static string IsEngine = "IsEngine";
420 static string Readme = "Readme";
421 static string GlobalNeeded = "GlobalNeeded";
422 static string Category = "Category";
423 static string Creator = "Creator";
424 while (! file.eof() )
425 {
426 getline (file,line);
427 vector<string> tokens;
428 vector<string>::iterator iter;
429 tokenize(line, tokens); //string to vector of "words"
430 if (tokens.capacity() >= 2) { //make sure they are using enough stuff
431 iter = tokens.begin(); //what word we are on, starts at first word
432 /*
433 if (!AEInstallVersion.compare(*iter))
434 If mod is too old, skip this mod.
435 */
436 /*else*/if (!NameOfMod.compare(*iter)) { //if it contains the name
437 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
438 if (ARROW.compare(*iter) && NameOfMod.compare(*iter)) { //ignores "->" and "NameOfMod"
439 //cout << *iter;
440 //cout << " ";
441 package.name += *iter + " ";
442 }
443 }
444
445 }
446 else if (!ModString.compare(*iter)) {
447 iter++; iter++;
448 package.modStringName = *iter;
449 iter++;
450 package.modStringVersion = atoi((*iter).c_str());
451 }
452 else if (!HasOnis.compare(*iter)) {
453 iter++; iter++;
454 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasOnis = 1; //Gotta love c++'s lack of a standard case-insensitive
455 else if (!HasBSL.compare(*iter)) { // string comparer...I know my implementation here sucks. I need to change it to check each character one by one. At the moment,
456 iter++; iter++; // using "YFR" would probably set it off. :<
457
458 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasBSL = 1;
459 }
460 else if (!HasDeltas.compare(*iter)) {
461 iter++; iter++;
462 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDeltas = 1;
463 }
464 else if (!HasDats.compare(*iter)) {
465 iter++; iter++;
466 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.hasDats = 1;
467 }
468 else if (!IsEngine.compare(*iter)) {
469 iter++; iter++;
470 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.isEngine = 1;
471 }
472 else if (!GlobalNeeded.compare(*iter)) {
473 iter++; iter++;
474 if (toupper((*iter)[0]) + toupper((*iter)[1]) + toupper((*iter)[2]) == 'Y' + 'E' + 'S') package.globalNeeded = 1;
475 else if (toupper((*iter)[0]) + toupper((*iter)[1]) == 'N' + 'O') package.globalNeeded = 1; //Really the only place where checking for "No" is important atm.
476 }
477 else if (!Category.compare(*iter)) {
478 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
479 if (ARROW.compare(*iter) && Category.compare(*iter)) { //ignores "->" and "Category"
480 //cout << *iter;
481 //cout << " ";
482 package.category += *iter + " ";
483 }
484 }
485 }
486 else if (!Creator.compare(*iter)) { //if it contains the name
487 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
488 if (ARROW.compare(*iter) && Creator.compare(*iter)) { //ignores "->" and "Category"
489 //cout << *iter;
490 //cout << " ";
491 package.creator += *iter + " ";
492 }
493 }
494 }
495 else if (!Readme.compare(*iter)) { //if it contains the name
496 for ( ; iter !=tokens.end() && SLASHSLASH.compare(*iter); iter++) { //interates through the words, ends if it reaches the end of the line or a "//" comment
497 if (ARROW.compare(*iter) && Readme.compare(*iter)) { //ignores "->" and "Category"
498 //cout << *iter;
499 //cout << " ";
500 package.readme += *iter + " ";
501 }
502 }
503 }
504 }
505
506 }
507 package.doOutput();
508 return package;
509}
510
511void recompileAll(vector<string> installedMods)
512{
513 cout << "Recompiling Data...\n";
514 path vanilla_dir = "./packages/VanillaDats/";
515 string importCommand = "";
516 if(splitInstances == SPLIT){
517 recursive_directory_iterator end_iter;
518 try {
519 for ( recursive_directory_iterator dir_itr( vanilla_dir );
520 dir_itr != end_iter;
521 ++dir_itr )
522 {
523 try
524 {
525 if ( is_directory( dir_itr->status() ) && dir_itr.level() == 1)
526 {
527 importCommand = strOniSplit + " " + strImportOption + " " + dir_itr->path().parent_path().string() + '/' + dir_itr->path().filename();
528 for (int i = 0; i < installedMods.size(); ++i) {
529 if (exists("packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename() ))
530 importCommand += " packages/" + installedMods[i] + "/oni/" + dir_itr->path().parent_path().filename() + '/' + dir_itr->path().filename();
531
532 //else cout << " packages/VanillaDats/" + installedMods[i] + "/oni/";
533 }
534 importCommand += " ../GameDataFolder/" + dir_itr->path().filename() + ".dat";
535 system(importCommand.c_str());
536 //cout << importCommand << "\n";
537 }
538 }
539 catch ( const std::exception & ex )
540 {
541 cout << "Warning, exception " << ex.what() << "!";
542 }
543 }
544 }
545 catch( const std::exception & ex ) {
546 cout << "Warning, exception " << ex.what() << "!\n"
547 << "You probably need to re-globalize.";
548 create_directory( "./packages/VanillaDats" );
549 }
550
551 }
552 else if(splitInstances == NOT_SPLIT){
553 directory_iterator end_iter;
554 for ( directory_iterator dir_itr( vanilla_dir );
555 dir_itr != end_iter;
556 ++dir_itr )
557 {
558 try
559 {
560 if ( is_directory( dir_itr->status() ) )
561 {
562 system((strOniSplit + " " + strImportOption + " " + vanilla_dir.string() + dir_itr->path().filename() + " " + "../GameDataFolder/" + dir_itr->path().filename()
563 + ".dat").c_str());
564 }
565 }
566 catch ( const std::exception & ex )
567 {
568 cout << "Warning, something odd happened!\n";
569 }
570 }
571 }
572}
573
574vector<string> getInstallString(void)
575{
576 system(strPauseCmd);
577 vector<string> returnval;
578 string file_name = "../GameDataFolder/ImportList.cfg";
579 string line;
580 fstream file;
581
582 if (exists(file_name))
583 {
584 file.open(file_name.c_str());
585 getline(file, line);
586 tokenize(line, returnval);
587 file.close();
588 file.clear();
589 sort(returnval.begin(), returnval.end());
590 }
591 else cout << "fail";
592
593 return returnval;
594}
595
596//stolen token function...
597void tokenize(const string& str, vector<string>& tokens, const string& delimiters)
598{
599 // Skip delimiters at beginning.
600 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
601 // Find first "non-delimiter".
602 string::size_type pos = str.find_first_of(delimiters, lastPos);
603
604 while (string::npos != pos || string::npos != lastPos)
605 {
606 // Found a token, add it to the vector.
607 tokens.push_back(str.substr(lastPos, pos - lastPos));
608 // Skip delimiters. Note the "not_of"
609 lastPos = str.find_first_not_of(delimiters, pos);
610 // Find next "non-delimiter"
611 pos = str.find_first_of(delimiters, lastPos);
612 }
613}
Note: See TracBrowser for help on using the repository browser.