Guest User

Untitled

a guest
Aug 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. QList<QTreeWidgetItem *> WitHandler::StringListToGameList( const QStringList &list, bool *okRet )
  2. {
  3.  
  4. int lines = list.size();
  5. bool ok = false;
  6. int gameCnt = -1;
  7. QString used;
  8. qint64 totalHddUsed = 0;
  9. int mode = 0;// 0 = hdd info, 1 = game info
  10. QList<QTreeWidgetItem *> games;
  11.  
  12. QString id;
  13. QString name;
  14. QString sizeStr;
  15. QString region;
  16. QString type;
  17. QString partitionInfo;
  18. QString path;
  19.  
  20. int currentGame = 0;
  21.  
  22. for( int j = 0; j < lines; j++ )
  23. {
  24. QString p = list.at( j );
  25. switch( mode )
  26. {
  27. case 0://get partition info
  28. {
  29. if( p.startsWith( "total-discs=" ) )//gamecount
  30. {
  31. p.remove( 0, p.indexOf( "=" ) + 1 );
  32. gameCnt = p.toInt( &ok );
  33. if( !ok || gameCnt < 0 )
  34. {
  35. qDebug() << "count" << p;
  36. goto abort;
  37. }
  38. if( !gameCnt )//just a HDD with no games
  39. {
  40. QTreeWidgetItem *size = new QTreeWidgetItem();//just tack the size onto the end of the list for now
  41. size->setText( 0, "0" );
  42. games << size;
  43. *okRet = true;
  44. return games;
  45. }
  46. continue;
  47. }
  48. if( p.startsWith( "total-size=" ) )//total size
  49. {
  50. p.remove( 0, p.indexOf( "=" ) + 1 );
  51. totalHddUsed = p.toDouble( &ok );
  52. if( !ok )
  53. {
  54. qDebug() << "size";
  55. goto abort;
  56. }
  57. used = p;
  58. if( gameCnt >= 0 )
  59. mode = 1;
  60.  
  61. qdebug() << "got teh partition info, gameCnt" << gameCnt << "totalHddUsed:" << totalHddUsed;
  62. continue;
  63. }
  64. }
  65. break;
  66. case 1://game info
  67. {
  68. if( p.startsWith( "id=" ) )
  69. {
  70. currentGame++;
  71. id = p;
  72. id.remove( 0, 3 );
  73.  
  74. if( namesFromWiiTDB )name = wiiTDB->NameFromID( id );//get the title from the wiitdb.zip
  75. continue;
  76. }
  77. if( p.startsWith( "name=" ) && ( !namesFromWiiTDB || name.isEmpty() ) )
  78. {
  79. name = p;
  80. name.remove( 0, 5 );
  81. continue;
  82. }
  83. if( p.startsWith( "title=" ) )//overwrite the title from the disc header with the one from titles.txt
  84. {
  85. QString title = p;
  86. title.remove( 0, 6 );
  87. if( title == "(null)" )
  88. continue;
  89.  
  90. name = title;
  91. continue;
  92. }
  93. if( p.startsWith( "region=" ) )
  94. {
  95. p.remove( 0, 7 );
  96. region = p;
  97. continue;
  98. }
  99. if( p.startsWith( "size=" ) )
  100. {
  101. p.remove( 0, 5 );
  102. sizeStr = p;
  103. //qDebug() << "list-lll" << sizeStr << name;
  104. continue;
  105. }
  106. if( p.startsWith( "filetype=" ) )
  107. {
  108. p.remove( 0, 9 );
  109. type = p;
  110. continue;
  111. }
  112. if( p.startsWith( "partition-info=" ) )
  113. {
  114. p.remove( 0, 15 );
  115. partitionInfo = p;
  116. continue;
  117. }
  118. if( p.startsWith( "source=" ) )
  119. {
  120. p.remove( 0, 7 );
  121. path = p;
  122.  
  123. if( !id.isEmpty() && !name.isEmpty() && !sizeStr.isEmpty() && !region.isEmpty() && !type.isEmpty() && !partitionInfo.isEmpty() && !path.isEmpty() )
  124. {
  125. QTreeWidgetItem *item = new QTreeWidgetItem();
  126. SetGameID( item, id );
  127. SetGameName( item, name );
  128. SetGameSize( item, sizeStr );
  129. SetGameRegion( item, region );
  130. SetGameType( item, type );
  131. SetGamePartitions( item, partitionInfo );
  132. SetGamePath( item, path );
  133.  
  134. games << item;
  135.  
  136. id.clear();
  137. name.clear();
  138. sizeStr.clear();
  139. region.clear();
  140. type.clear();
  141. partitionInfo.clear();
  142. path.clear();
  143.  
  144. if( games.size() == gameCnt )
  145. {
  146. QTreeWidgetItem *size = new QTreeWidgetItem();//just tack the size onto the end of the list for now
  147. size->setText( 0, used );
  148. games << size;
  149. *okRet = true;
  150. return games;
  151. }
  152. }
  153. else
  154. {
  155. qDebug() << "error parsing game" << currentGame;
  156. qDebug() << id << name << sizeStr << region << type << partitionInfo << path;
  157.  
  158. }
  159. }
  160. }
  161. break;
  162. default:
  163. qDebug() << "list-lll case";
  164. goto abort;
  165. break;
  166. }
  167. }
  168. qDebug() << "list-lll wtf";
  169. abort:
  170. while( !games.isEmpty() )
  171. {
  172. QTreeWidgetItem *shit = games.takeFirst();
  173. delete shit;
  174. }
  175. *okRet = false;
  176. emit SendFatalErr( tr( "wit LIST-LLL returned invalid list of games" ), witListLLLHDD );
  177. return games;
  178.  
  179. }
Add Comment
Please, Sign In to add comment