verctrl.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. // verctrl.cpp : Defines the entry point for the console application.
  2. //
  3. #include "verctrl.h"
  4. static char *branding = 0;
  5. int _tmain(int argc, _TCHAR* argv[])
  6. {
  7. _tprintf(_T("Version Control Utility ver 1.0\n"));
  8. _tprintf(_T("Patching version information in the winamp project source files\n\n"));
  9. bool setted = false;
  10. if (argc > 1)
  11. {
  12. if (0 == _tcsicmp(argv[1], _T("QA")))
  13. {
  14. type = Beta;
  15. setted = true;
  16. }
  17. else if (0 == _tcsicmp(argv[1], _T("BETA")))
  18. {
  19. type = Beta;
  20. setted = true;
  21. }
  22. else if (0 == _tcsicmp(argv[1], _T("NIGHT")))
  23. {
  24. type = Night;
  25. setted = true;
  26. }
  27. else if (0 == _tcsicmp(argv[1], _T("FINAL")))
  28. {
  29. type = Final;
  30. setted = true;
  31. }
  32. }
  33. if (argc > 2)
  34. {
  35. branding = strdup(argv[2]);
  36. }
  37. else
  38. branding=_T("");
  39. if (!setted)
  40. {
  41. Help();
  42. _tprintf(_T("\nError! Not enough arguments.\n"));
  43. return 1;
  44. }
  45. else
  46. {
  47. _tprintf(_T("Build Type: "));
  48. switch(type)
  49. {
  50. case Final:
  51. _tprintf(_T("FINAL"));
  52. break;
  53. case Beta:
  54. _tprintf(_T("BETA"));
  55. break;
  56. case Night:
  57. _tprintf(_T("NIGHT"));
  58. break;
  59. }
  60. _tprintf(_T("\n"));
  61. _tprintf(_T("Branding: %s\n"), branding);
  62. _tprintf(_T("\n"));
  63. }
  64. InitData();
  65. _tprintf(_T("Reading version info... "));
  66. if (!LoadInfoFile())
  67. {
  68. _tprintf(_T("Failed\n\nError! Unable to load version data from '%s'.\n\n"), verInfoFileName);
  69. return 1;
  70. }
  71. _tprintf(_T("Ok\n"));
  72. _tprintf(_T("Reading build info... "));
  73. if (!LoadBuildNumber())
  74. {
  75. _tprintf(_T("Failed\n\nError! Unable to load version data from '%s'.\n\n"), verBuildFileName);
  76. return 1;
  77. }
  78. _tprintf(_T("Ok\n"));
  79. if (argc > 3 && (0 == _tcsicmp(argv[3], _T("inc")))) ver_build++; // increment build number
  80. _tprintf(_T("Checking version info data... "));
  81. if (!AllValuesSet())
  82. {
  83. _tprintf(_T("Failed\n\nError! Not all version data is set. Check version information files syntax.\n\n"));
  84. return 1;
  85. }
  86. _tprintf(_T("Ok\n"));
  87. bool success[9];
  88. for(int i = 0; i < sizeof(success)/sizeof(success[0]); i++) success[i] = true;
  89. _tprintf(_T("\nPatching '%s' "), fileConstantsH);
  90. if (!PatchConstantsH()) { _tprintf(_T("Failed\n")); success[0] = false;}
  91. else _tprintf(_T("Ok\n"));
  92. _tprintf(_T("Patching '%s' "), fileVerInfoNSH);
  93. if (!PatchVerInfoNSH()) { _tprintf(_T("Failed\n")); success[1] = false;}
  94. else _tprintf(_T("Ok\n"));
  95. _tprintf(_T("Patching '%s' "), fileMainH);
  96. if (!PatchMainH()) { _tprintf(_T("Failed\n")); success[2] = false;}
  97. else _tprintf("Ok\n");
  98. _tprintf(_T("Patching '%s' "), fileBuildTypeH);
  99. if (!PatchBuildTypeH()) { _tprintf(_T("Failed\n")); success[3] = false;}
  100. else _tprintf("Ok\n");
  101. _tprintf(_T("Patching '%s' "), fileWasabiCfgH);
  102. if (!PatchWasabiCfgH()) { _tprintf(_T("Failed\n")); success[4] = false;}
  103. else _tprintf("Ok\n");
  104. _tprintf(_T("Patching '%s' "), fileManifest);
  105. if (!PatchManifest(fileManifest)) { _tprintf(_T("Failed\n")); success[5] = false;}
  106. else _tprintf("Ok\n");
  107. _tprintf(_T("Patching '%s' "), fileManifest64);
  108. if (!PatchManifest(fileManifest64)) { _tprintf(_T("Failed\n")); success[6] = false;}
  109. else _tprintf("Ok\n");
  110. _tprintf(_T("Patching '%s' "), fileFileNamesCmd);
  111. if (!PatchFileNamesCmd()) { _tprintf(_T("Failed\n")); success[7] = false;}
  112. else _tprintf("Ok\n");
  113. _tprintf(_T("Patching '%s' "), fileMakeNsisCmd);
  114. if (!PatchMakeNsisCmd()) { _tprintf(_T("Failed\n")); success[8] = false;}
  115. else _tprintf("Ok\n");
  116. _tprintf(_T("Patching '%s' "), fileTalkbackIni);
  117. if (!PatchTalkbackIni()) { _tprintf(_T("Failed\n")); success[9] = false;}
  118. else _tprintf("Ok\n");
  119. _tprintf(_T("\n"));
  120. bool iserr = false;
  121. for (int i = 0 ; i <9 ; i++)
  122. {
  123. if (!success[i])
  124. {
  125. iserr = true;
  126. TCHAR const *fn;
  127. switch(i)
  128. {
  129. case 0:
  130. fn = fileConstantsH;
  131. break;
  132. case 1:
  133. fn = fileVerInfoNSH;
  134. break;
  135. case 2:
  136. fn = fileMainH;
  137. break;
  138. case 3:
  139. fn = fileBuildTypeH;
  140. break;
  141. case 4:
  142. fn = fileWasabiCfgH;
  143. break;
  144. case 5:
  145. fn = fileManifest;
  146. break;
  147. case 6:
  148. fn = fileManifest64;
  149. break;
  150. case 7:
  151. fn = fileFileNamesCmd;
  152. break;
  153. case 8:
  154. fn = fileMakeNsisCmd;
  155. break;
  156. case 9:
  157. fn = fileTalkbackIni;
  158. break;
  159. }
  160. _tprintf(_T("Error! Unable to patch file - '%s'.\n"), fn);
  161. }
  162. }
  163. if (iserr)
  164. {
  165. _tprintf(_T("\nData patched with errors.\n\n"));
  166. }
  167. else
  168. {
  169. _tprintf(_T("Data patched successfully.\n\n"));
  170. }
  171. return 0;
  172. }
  173. void InitData(void)
  174. {
  175. ver_major = 5;
  176. ver_minor = 0;
  177. ver_minor2 = 0;
  178. ver_build = 0;
  179. ver_api[0] = 0;
  180. }
  181. bool LoadInfoFile(void)
  182. {
  183. FILE* pstream;
  184. if( (pstream = _tfsopen( verInfoFileName, "r", 0x20 )) == NULL )
  185. return false;
  186. fseek( pstream, 0L, SEEK_SET );
  187. TCHAR line[LINE_LENGTH];
  188. while( !feof(pstream) )
  189. {
  190. _fgetts(line,LINE_LENGTH,pstream);
  191. RemoveCrap(line, (int)_tcslen(line));
  192. ParseLine(line);
  193. }
  194. fclose(pstream);
  195. return true;
  196. }
  197. bool LoadBuildNumber(void)
  198. {
  199. FILE* pstream;
  200. if( (pstream = _tfsopen( verBuildFileName, "r", 0x20 )) == NULL )
  201. return false;
  202. fseek( pstream, 0L, SEEK_SET );
  203. TCHAR line[LINE_LENGTH];
  204. while( !feof(pstream) )
  205. {
  206. _fgetts(line,LINE_LENGTH,pstream);
  207. if (_tcsstr(line, _T("DG_BUILD_NUMBER")) != NULL)
  208. {
  209. TCHAR *end;
  210. end = line + (int)_tcslen(line) -1;
  211. while (end[0] <= 32) {end[0] = 0; end--;}
  212. while ( end[0] >= _T('0') && end[0] <= _T('9') ) end--;
  213. if ((int)_tcslen(line) > 0)
  214. {
  215. _stscanf(end, "%d", &ver_build);
  216. }
  217. }
  218. }
  219. fclose(pstream);
  220. return true;
  221. }
  222. void ParseLine(TCHAR* line)
  223. {
  224. TCHAR *name, *value;
  225. int pos = 0;
  226. while (line[pos] != _T('=') && line[pos] != 0) pos++;
  227. if (pos == 0) return; // no name
  228. name = line;
  229. line[pos] = 0;
  230. value = line + pos +1;
  231. if (0 == _tcscmp(name, _T("VERSION_MAJOR"))) _stscanf(value, "%d", &ver_major);
  232. else if (0 == _tcscmp(name, _T("VERSION_MINOR"))) _stscanf(value, "%d", &ver_minor);
  233. // look if VERSION_MINOR_SECOND more than one char length only first one goes to the number
  234. else if (0 == _tcscmp(name, _T("VERSION_MINOR_SECOND")))
  235. {
  236. _tcscpy(ver_minor2_full, value);
  237. if (_tcslen(value) > 1) value[1] = 0x00;
  238. if (!_tcscmp(ver_minor2_full, _T("0")))
  239. _tcscpy(ver_minor2_full, _T(""));
  240. _stscanf(value, "%d", &ver_minor2);
  241. }
  242. else if (0 == _tcscmp(name, _T("VERSION_API"))) _tcscpy(ver_api, value);
  243. }
  244. TCHAR* RemoveCrap(TCHAR* str, int len)
  245. {
  246. int pos = 0;
  247. while (pos < len)
  248. {
  249. if (str[pos] < 33)
  250. {
  251. for (int i = pos + 1; i < len; i++) str[i -1] = str[i];
  252. str[len-1] = 0;
  253. len --;
  254. }
  255. else pos++;
  256. }
  257. return str;
  258. }
  259. bool AllValuesSet(void)
  260. {
  261. return !((ver_major > -1) && (ver_minor > -1) && (ver_minor2 > -1) && (ver_build > -1) > (ver_api[0] > 0));
  262. }
  263. bool PatchConstantsH(void)
  264. {
  265. FILE *streamIn, *streamOut;
  266. if( (streamIn = _tfsopen( fileConstantsH, "r", 0x20 )) == NULL ) return false;
  267. fseek( streamIn, 0L, SEEK_SET );
  268. streamOut = tmpfile();
  269. fseek( streamOut, 0L, SEEK_SET );
  270. const TCHAR* lookFor = _T("#define DG_VERSION /*CFGMGMT_VERSION*/");
  271. TCHAR line[LINE_LENGTH];
  272. while( !feof(streamIn) )
  273. {
  274. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  275. if (NULL != _tcsstr(line, lookFor))
  276. {
  277. TCHAR *data;
  278. data = line + (int)_tcslen(lookFor);
  279. const TCHAR ending[128] = _T("\"\n\0");
  280. TCHAR newStr[256];
  281. _stprintf(newStr, _T(" \"%d.%d.%d"), ver_major, ver_minor, ver_minor2);
  282. switch(type)
  283. {
  284. case Beta:
  285. _tcscat(newStr,_T(" Beta"));
  286. break;
  287. case Night:
  288. _tcscat(newStr,_T(" Nightly"));
  289. break;
  290. }
  291. _tcscat(newStr, ending);
  292. _tcscpy(data, newStr);
  293. }
  294. _fputts(line, streamOut);
  295. }
  296. _fputts( _T("\n\0"), streamOut);
  297. fflush(streamOut);
  298. if( _tfreopen(fileConstantsH, "w+", streamIn) == NULL ) return false;
  299. fcopy(streamIn, streamOut);
  300. fclose(streamOut);
  301. fclose(streamIn);
  302. return true;
  303. }
  304. bool PatchVerInfoNSH(void)
  305. {
  306. FILE *streamIn, *streamOut;
  307. if( (streamIn = _tfsopen( fileVerInfoNSH, "rb", 0x20 )) == NULL ) return false;
  308. fseek( streamIn, 0L, SEEK_SET );
  309. streamOut = tmpfile();
  310. fseek( streamOut, 0L, SEEK_SET );
  311. wchar_t line[LINE_LENGTH];
  312. wchar_t *data;
  313. const wchar_t ending[] = L"\"\n\0";
  314. wchar_t newStr[256];
  315. const wchar_t lookMajor[] = L"VERSION_MAJOR";
  316. const wchar_t lookMin[] = L"VERSION_MINOR";
  317. const wchar_t lookMin2[] = L"VERSION_MINOR_SECOND";
  318. const wchar_t lookMin3[] = L"VERSION_MINOR_SECOND_SHORT";
  319. const wchar_t lookBuild[] = L"BUILD_NUM";
  320. wchar_t *start;
  321. wchar_t BOM = 0xFEFF;
  322. fwrite(&BOM, sizeof(BOM), 1, streamOut);
  323. switch(type)
  324. {
  325. case Beta:
  326. fputws(L"!define BETA\n\0", streamOut);
  327. break;
  328. case Night:
  329. fputws(L"!define NIGHT\n\0", streamOut);
  330. break;
  331. }
  332. fread(&BOM, 2, 1, streamIn);
  333. while( !feof(streamIn) )
  334. {
  335. if (NULL == fgetws(line,LINE_LENGTH, streamIn)) continue;
  336. if (NULL != wcsstr(line, L"!define"))
  337. {
  338. if (NULL != (start = wcsstr(line, lookMajor)))
  339. {
  340. data = start + (int)wcslen(lookMajor);
  341. swprintf(newStr, L" \"%d%s", ver_major, ending);
  342. wcscpy(data, newStr);
  343. }
  344. else if (NULL != (start = wcsstr(line, lookMin3)))
  345. {
  346. data = start + (int)wcslen(lookMin3);
  347. swprintf(newStr, L" \"%d%s", ver_minor2, ending);
  348. wcscpy(data, newStr);
  349. }
  350. else if (NULL != (start = wcsstr(line, lookMin2)))
  351. {
  352. data = start + (int)wcslen(lookMin2);
  353. swprintf(newStr, L" \"%S%s", ver_minor2_full, ending);
  354. wcscpy(data, newStr);
  355. }
  356. else if (NULL != (start = wcsstr(line, lookMin)))
  357. {
  358. data = start + (int)wcslen(lookMin);
  359. if (L' ' == data[0])
  360. {
  361. swprintf(newStr, L" \"%d%s", ver_minor, ending);
  362. wcscpy(data, newStr);
  363. }
  364. }
  365. else if (NULL != (start = wcsstr(line, lookBuild)))
  366. {
  367. data = start + (int)wcslen(lookBuild);
  368. swprintf(newStr, L" \"%d%s", ver_build, ending);
  369. wcscpy(data, newStr);
  370. }
  371. else if (NULL != wcsstr(line, L"BETA") || NULL != wcsstr(line, L"NIGHT")) continue; // ignore it - we will define it on our one :)
  372. }
  373. fputws(line, streamOut);
  374. }
  375. fputws( L"\n\0", streamOut);
  376. fflush(streamOut);
  377. if( _tfreopen(fileVerInfoNSH, "w+b", streamIn) == NULL ) return false;
  378. fwcopy(streamIn, streamOut);
  379. fclose(streamOut);
  380. fclose(streamIn);
  381. return true;
  382. }
  383. bool PatchMainH(void)
  384. {
  385. FILE *streamIn, *streamOut;
  386. if( (streamIn = _tfsopen( fileMainH, "r", 0x20 )) == NULL ) return false;
  387. fseek( streamIn, 0L, SEEK_SET );
  388. streamOut = tmpfile();
  389. fseek( streamOut, 0L, SEEK_SET );
  390. TCHAR line[LINE_LENGTH];
  391. TCHAR *data;
  392. const TCHAR ending[128] = _T("\"\n\0");
  393. TCHAR version[128];
  394. TCHAR versionStr[128];
  395. TCHAR newStr[256];
  396. const TCHAR lookBuildNumber[128] = _T("#define BUILD_NUMBER");
  397. const TCHAR lookVer[128] = _T("#define APP_VERSION");
  398. const TCHAR lookAPI[128] = _T("_NUM");
  399. const TCHAR lookStr[128] = _T("_STRING");
  400. TCHAR *start;
  401. _stprintf(version, _T("%d.%d%s"), ver_major, ver_minor, ver_minor2_full);
  402. /*if (Final == type)
  403. {
  404. _stprintf(versionStr, _T("%d.%d%s"), ver_major, ver_minor, ver_minor2_full);
  405. }
  406. else*/
  407. {
  408. _stprintf(versionStr, _T("%d.%d%s Build %d"), ver_major, ver_minor, ver_minor2_full, ver_build);
  409. }
  410. switch(type)
  411. {
  412. case Beta:
  413. _tcscat(versionStr,_T(" Beta"));
  414. break;
  415. case Night:
  416. _tcscat(versionStr,_T(" Nightly"));
  417. break;
  418. }
  419. while( !feof(streamIn) )
  420. {
  421. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  422. if (NULL != _tcsstr(line, lookVer) )
  423. {
  424. if (NULL != (start = _tcsstr(line, lookAPI)))
  425. {
  426. data = start + (int)_tcslen(lookAPI);
  427. _stprintf(newStr, _T(" %s\n\0"), ver_api);
  428. _tcscpy(data, newStr);
  429. }
  430. else if (NULL != (start = _tcsstr(line, lookStr)))
  431. {
  432. data = start + (int)_tcslen(lookStr);
  433. _stprintf(newStr, _T(" \"%s%s"), versionStr, ending);
  434. _tcscpy(data, newStr);
  435. }
  436. else
  437. {
  438. data = line + (int)_tcslen(lookVer);
  439. if (_T(' ') == data[0] ) // just a version
  440. {
  441. _stprintf(newStr, _T(" \"%s%s"), version, ending);
  442. _tcscpy(data, newStr);
  443. }
  444. }
  445. }
  446. else if (NULL != _tcsstr(line, lookBuildNumber))
  447. {
  448. data = line + (int)_tcslen(lookBuildNumber);
  449. if (_T(' ') == data[0] ) // just a version
  450. {
  451. _stprintf(newStr, _T(" %d"), ver_build);
  452. _tcscpy(data, newStr);
  453. }
  454. }
  455. _fputts(line, streamOut);
  456. }
  457. _fputts( _T("\n\0"), streamOut);
  458. fflush(streamOut);
  459. if( _tfreopen(fileMainH, "w+", streamIn) == NULL ) return false;
  460. fcopy(streamIn, streamOut);
  461. fclose(streamOut);
  462. fclose(streamIn);
  463. return true;
  464. }
  465. bool PatchTalkbackIni(void)
  466. {
  467. FILE *streamIn, *streamOut;
  468. if( (streamIn = _tfsopen( fileTalkbackIni, "r", 0x20 )) == NULL ) return false;
  469. fseek( streamIn, 0L, SEEK_SET );
  470. streamOut = tmpfile();
  471. fseek( streamOut, 0L, SEEK_SET );
  472. TCHAR line[LINE_LENGTH];
  473. const TCHAR ending[128] = _T("\"\n\0");
  474. while( !feof(streamIn) )
  475. {
  476. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  477. if (line == _tcsstr(line, _T("BuildID = \"")))
  478. {
  479. _stprintf(line, _T("BuildID = \"%d\"\n\0"), ver_build);
  480. }
  481. _fputts(line, streamOut);
  482. }
  483. _fputts( _T("\n\0"), streamOut);
  484. fflush(streamOut);
  485. if( _tfreopen(fileTalkbackIni, "w+", streamIn) == NULL ) return false;
  486. fcopy(streamIn, streamOut);
  487. fclose(streamOut);
  488. fclose(streamIn);
  489. return true;
  490. }
  491. bool PatchBuildTypeH(void)
  492. {
  493. FILE *streamIn, *streamOut;
  494. if( (streamIn = _tfsopen( fileBuildTypeH, "r", 0x20 )) == NULL ) return false;
  495. fseek( streamIn, 0L, SEEK_SET );
  496. streamOut = tmpfile();
  497. fseek( streamOut, 0L, SEEK_SET );
  498. TCHAR line[LINE_LENGTH];
  499. const TCHAR ending[128] = _T("\"\n\0");
  500. const TCHAR lookBeta[128] = _T("#define BETA");
  501. const TCHAR lookNight[128] = _T("#define NIGHT");
  502. const TCHAR lookInternal[128] = _T("#define INTERNAL");
  503. const TCHAR lookNokia[128] = _T("#define NOKIA");
  504. while( !feof(streamIn) )
  505. {
  506. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  507. if (NULL != _tcsstr(line, lookBeta))
  508. {
  509. if (Beta == type) _stprintf(line, _T("%s\n\0"), lookBeta);
  510. else _stprintf(line, _T("/*%s*/\n\0"), lookBeta);
  511. }
  512. else if (NULL != _tcsstr(line, lookNight))
  513. {
  514. if (Night == type) _stprintf(line, _T("%s\n\0"), lookNight);
  515. else _stprintf(line, _T("/*%s*/\n\0"), lookNight);
  516. }
  517. else if (NULL != _tcsstr(line, lookInternal))
  518. {
  519. if (Night == type) _stprintf(line, _T("%s\n\0"), lookInternal);
  520. else _stprintf(line, _T("/*%s*/\n\0"), lookInternal);
  521. }
  522. else if (NULL != _tcsstr(line, lookNokia))
  523. {
  524. if (!stricmp(branding, "NOKIA")) _stprintf(line, _T("%s\n\0"), lookNokia);
  525. else _stprintf(line, _T("/*%s*/\n\0"), lookNokia);
  526. }
  527. _fputts(line, streamOut);
  528. }
  529. _fputts( _T("\n\0"), streamOut);
  530. fflush(streamOut);
  531. if( _tfreopen(fileBuildTypeH, "w+", streamIn) == NULL ) return false;
  532. fcopy(streamIn, streamOut);
  533. fclose(streamOut);
  534. fclose(streamIn);
  535. return true;
  536. }
  537. bool PatchWasabiCfgH(void)
  538. {
  539. FILE *streamIn, *streamOut;
  540. if( (streamIn = _tfsopen( fileWasabiCfgH, "r", 0x20 )) == NULL ) return false;
  541. fseek( streamIn, 0L, SEEK_SET );
  542. streamOut = tmpfile();
  543. fseek( streamOut, 0L, SEEK_SET );
  544. TCHAR line[LINE_LENGTH];
  545. const TCHAR ending[128] = _T("\"\n\0");
  546. const TCHAR lookBeta[128] = _T("#define BETA");
  547. const TCHAR lookNight[128] = _T("#define NIGHT");
  548. const TCHAR lookNokia[128] = _T("#define NOKIA");
  549. while( !feof(streamIn) )
  550. {
  551. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  552. if (NULL != _tcsstr(line, lookBeta))
  553. {
  554. if (Beta == type) _stprintf(line, _T("%s\n\0"), lookBeta);
  555. else _stprintf(line, _T("/*%s*/\n\0"), lookBeta);
  556. }
  557. else if (NULL != _tcsstr(line, lookNight))
  558. {
  559. if (Night == type) _stprintf(line, _T("%s\n\0"), lookNight);
  560. else _stprintf(line, _T("/*%s*/\n\0"), lookNight);
  561. }
  562. else if (NULL != _tcsstr(line, lookNokia))
  563. {
  564. if (!stricmp(branding, "NOKIA")) _stprintf(line, _T("%s\n\0"), lookNokia);
  565. else _stprintf(line, _T("/*%s*/\n\0"), lookNokia);
  566. }
  567. _fputts(line, streamOut);
  568. }
  569. _fputts( _T("\n\0"), streamOut);
  570. fflush(streamOut);
  571. if( _tfreopen(fileWasabiCfgH, "w+", streamIn) == NULL ) return false;
  572. fcopy(streamIn, streamOut);
  573. fclose(streamOut);
  574. fclose(streamIn);
  575. return true;
  576. }
  577. bool PatchFileNamesCmd(void)
  578. {
  579. FILE *streamIn, *streamOut;
  580. if( (streamIn = _tfsopen( fileFileNamesCmd, "r", 0x20 )) == NULL ) return false;
  581. fseek( streamIn, 0L, SEEK_SET );
  582. streamOut = tmpfile();
  583. fseek( streamOut, 0L, SEEK_SET );
  584. TCHAR *data;
  585. TCHAR newStr[LINE_LENGTH];
  586. TCHAR line[LINE_LENGTH];
  587. const TCHAR ending[] = _T("\n\0");
  588. const TCHAR lookStr[] = _T("SET INSTALL_NAME");
  589. while( !feof(streamIn) )
  590. {
  591. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  592. if (NULL != _tcsstr(line, lookStr))
  593. {
  594. data = line + (int)_tcslen(lookStr);
  595. _stprintf(newStr, _T("=winamp%d%d%s"), ver_major, ver_minor, ver_minor2_full);
  596. TCHAR tmp[64];
  597. switch(type)
  598. {
  599. case Beta:
  600. case Night:
  601. _stprintf(tmp, ((Beta == type) ? "_%04d_beta" : "_%04d_nightly"), ver_build);
  602. _tcscat(newStr,tmp);
  603. break;
  604. }
  605. _tcscat(newStr, ending);
  606. _tcscpy(data, newStr);
  607. }
  608. _fputts(line, streamOut);
  609. }
  610. _fputts( _T("\n\0"), streamOut);
  611. fflush(streamOut);
  612. if( _tfreopen(fileFileNamesCmd, "w+", streamIn) == NULL ) return false;
  613. fcopy(streamIn, streamOut);
  614. fclose(streamOut);
  615. fclose(streamIn);
  616. return true;
  617. }
  618. bool PatchMakeNsisCmd(void)
  619. {
  620. FILE *streamIn, *streamOut;
  621. if( (streamIn = _tfsopen( fileMakeNsisCmd, "r", 0x20 )) == NULL ) return false;
  622. fseek( streamIn, 0L, SEEK_SET );
  623. streamOut = tmpfile();
  624. fseek( streamOut, 0L, SEEK_SET );
  625. TCHAR *data;
  626. TCHAR newStr[LINE_LENGTH];
  627. TCHAR line[LINE_LENGTH];
  628. const TCHAR ending[] = _T("\n\0");
  629. const TCHAR *szLookTable[] =
  630. {
  631. _T("SET WINAMP_VERSION_MAJOR"),
  632. _T("SET WINAMP_VERSION_MINOR_SECOND"),
  633. _T("SET WINAMP_VERSION_MINOR"),
  634. };
  635. while( !feof(streamIn) )
  636. {
  637. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  638. for (int i = 0; i < sizeof(szLookTable)/sizeof(szLookTable[0]); i++)
  639. {
  640. TCHAR *p = _tcsstr(line, szLookTable[i]);
  641. if (NULL != p && *(p + _tcslen(szLookTable[i])) != _T('_'))
  642. {
  643. data = line + (int)_tcslen( szLookTable[i]);
  644. switch(i)
  645. {
  646. case 0: _stprintf(newStr, _T("=%d"), ver_major); break;
  647. case 1: _stprintf(newStr, _T("=%s"), ver_minor2_full); break;
  648. case 2: _stprintf(newStr, _T("=%d"), ver_minor); break;
  649. }
  650. _tcscat(newStr, ending);
  651. _tcscpy(data, newStr);
  652. }
  653. }
  654. _fputts(line, streamOut);
  655. }
  656. _fputts( _T("\n\0"), streamOut);
  657. fflush(streamOut);
  658. if( _tfreopen(fileMakeNsisCmd, "w+", streamIn) == NULL ) return false;
  659. fcopy(streamIn, streamOut);
  660. fclose(streamOut);
  661. fclose(streamIn);
  662. return true;
  663. }
  664. bool PatchManifest(const TCHAR *fn)
  665. {
  666. FILE *streamIn, *streamOut;
  667. if( (streamIn = _tfsopen( fn, "r", 0x20 )) == NULL ) return false;
  668. fseek( streamIn, 0L, SEEK_SET );
  669. streamOut = tmpfile();
  670. fseek( streamOut, 0L, SEEK_SET );
  671. TCHAR line[LINE_LENGTH];
  672. TCHAR *data;
  673. const TCHAR ending[128] = _T("\"\n\0");
  674. TCHAR version[128];
  675. TCHAR newStr[256];
  676. const TCHAR lookSec[128] = _T("<assemblyIdentity");
  677. const TCHAR lookSecEnd[4] = _T("/>");
  678. const TCHAR lookVer[128] = _T("version");
  679. _stprintf(version, _T("%d.%d.%d.%d"), ver_major, ver_minor, ver_minor2, ver_build);
  680. bool fixed = false;
  681. bool inSection = false;
  682. TCHAR *start;
  683. while( !feof(streamIn) )
  684. {
  685. if (NULL == _fgetts(line,LINE_LENGTH, streamIn)) continue;
  686. if (!fixed)
  687. {
  688. if (NULL != _tcsstr(line, lookSec) )
  689. {
  690. inSection = true;
  691. }
  692. else if(NULL != _tcsstr(line, lookSecEnd) )
  693. {
  694. if (inSection) fixed = true; // protection allows only ones to came to the section
  695. inSection = false;
  696. }
  697. else if (inSection && (NULL != (start = _tcsstr(line, lookVer))))
  698. {
  699. data = start + (int)_tcslen(lookVer);
  700. _stprintf(newStr, _T("=\"%s%s"), version, ending);
  701. _tcscpy(data, newStr);
  702. fixed = true;
  703. }
  704. }
  705. _fputts(line, streamOut);
  706. }
  707. _fputts( _T("\n\0"), streamOut);
  708. fflush(streamOut);
  709. if( _tfreopen(fn, "w+", streamIn) == NULL ) return false;
  710. fcopy(streamIn, streamOut);
  711. fclose(streamOut);
  712. fclose(streamIn);
  713. return true;
  714. }
  715. void fcopy (FILE *dest, FILE *source)
  716. {
  717. char line[LINE_LENGTH];
  718. fseek(source, 0L, SEEK_SET );
  719. fseek(dest, 0L, SEEK_SET );
  720. _fgetts( line, LINE_LENGTH, source );
  721. while(!feof(source))
  722. {
  723. _fputts(line,dest);
  724. _fgetts( line, LINE_LENGTH, source );
  725. }
  726. }
  727. void fwcopy (FILE *dest, FILE *source)
  728. {
  729. wchar_t line[LINE_LENGTH];
  730. fseek(source, 0L, SEEK_SET );
  731. fseek(dest, 0L, SEEK_SET );
  732. fgetws( line, LINE_LENGTH, source );
  733. while(!feof(source))
  734. {
  735. fputws(line,dest);
  736. fgetws( line, LINE_LENGTH, source );
  737. }
  738. }
  739. void Help(void)
  740. {
  741. _tprintf(_T("Usage: verctrl..exe NIGHT|BETA|FINAL [INC]\n"));
  742. _tprintf(_T(" NIGHT - night build\n"));
  743. _tprintf(_T(" BETA - beta build\n"));
  744. _tprintf(_T(" FINAL - final build\n\n"));
  745. _tprintf(_T(" INC - increment build number\n"));
  746. }