Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

258 lines
7.6 KiB

  1. #include "headers.hxx"
  2. #include "..\CSVDSReader.hpp"
  3. #include "..\constants.hpp"
  4. #include "..\global.hpp"
  5. HINSTANCE hResourceModuleHandle = 0;
  6. const wchar_t* HELPFILE_NAME = 0; // no context help available
  7. const wchar_t* RUNTIME_NAME = L"W2KStrs";
  8. DWORD DEFAULT_LOGGING_OPTIONS =
  9. Log::OUTPUT_TO_FILE
  10. | Log::OUTPUT_FUNCCALLS
  11. | Log::OUTPUT_LOGS
  12. | Log::OUTPUT_ERRORS
  13. | Log::OUTPUT_HEADER;
  14. Popup popup(L"W2KStrs", false);
  15. // Keep all printable characters and escape the others.
  16. // Escaping means representing the character as &xxxx
  17. // where the x is an hexadecimal digit
  18. // This routine also replaces & for &&
  19. // The unescape function is in ..\global.cpp
  20. String escape(const wchar_t *str)
  21. {
  22. LOG_FUNCTION(escape);
  23. String dest;
  24. wchar_t strNum[5];
  25. while(*str!=0)
  26. {
  27. if(*str=='&')
  28. {
  29. dest+=L"&&";
  30. }
  31. else
  32. {
  33. if (
  34. (*str >= L'a' && *str <= L'z') ||
  35. (*str >= L'A' && *str <= L'Z') ||
  36. (*str >= L'0' && *str <= L'9') ||
  37. wcschr(L" !@#$%^*()-_=+[{]}\"';:.>,</?\\|",*str)!=NULL
  38. )
  39. {
  40. dest+=*str;
  41. }
  42. else
  43. {
  44. // I know that a w_char as a string will have
  45. // exactly 4 hexadecimal digits, so this is one of
  46. // the very rare wsprintfs that can be considered safe :)
  47. wsprintf(strNum,L"&%04x",*str);
  48. dest+=String(strNum);
  49. }
  50. }
  51. str++;
  52. }
  53. return dest;
  54. }
  55. int WINAPI
  56. WinMain(
  57. HINSTANCE /*hInstance*/,
  58. HINSTANCE /*hPrevInstance */ ,
  59. LPSTR /*lpszCmdLine, */,
  60. int /*nCmdShow */)
  61. {
  62. LOG_FUNCTION(WinMain);
  63. int argv;
  64. LPWSTR *argc=CommandLineToArgvW(GetCommandLine(),&argv);
  65. if(argv!=3)
  66. {
  67. MessageBox(NULL,L"Usage: W2KStrs dcpromo2k.csv out.txt",L"Error",MB_OK);
  68. return 0;
  69. }
  70. HRESULT hr=S_OK;
  71. HANDLE file=INVALID_HANDLE_VALUE;
  72. const wchar_t *W2KFile =argc[1];
  73. const wchar_t *outFile =argc[2];
  74. do
  75. {
  76. CSVDSReader csvIntlW2K;
  77. hr=csvIntlW2K.read(W2KFile,LOCALEIDS);
  78. BREAK_ON_FAILED_HRESULT(hr);
  79. hr=FS::CreateFile( outFile,
  80. file,
  81. GENERIC_WRITE);
  82. if FAILED(hr)
  83. {
  84. MessageBox(NULL,L"Problems during generation",L"Error",MB_OK);
  85. LOG_HRESULT(hr);
  86. return hr;
  87. }
  88. for(long l=0;LOCALEIDS[l]!=0;l++)
  89. {
  90. for( long i = 0;
  91. *(CHANGE_LIST[i].object)!=0;
  92. i++)
  93. {
  94. wchar_t *object = CHANGE_LIST[i].object;
  95. for( long c = 0;
  96. *(CHANGE_LIST[i].changes[c].property)!=0;
  97. c++)
  98. {
  99. enum TYPE_OF_CHANGE type;
  100. type = CHANGE_LIST[i].changes[c].type;
  101. if(
  102. type == REPLACE_W2K_SINGLE_VALUE ||
  103. type == REPLACE_W2K_MULTIPLE_VALUE
  104. )
  105. {
  106. wchar_t *property = CHANGE_LIST[i].changes[c].property;
  107. wchar_t *value = CHANGE_LIST[i].changes[c].value;
  108. long locale = LOCALEIDS[l];
  109. String W2KValue;
  110. // The goal of if and else is getting the W2KValue
  111. if(type==REPLACE_W2K_SINGLE_VALUE)
  112. {
  113. StringList valuesW2K;
  114. hr=csvIntlW2K.getCsvValues(locale,object,property,valuesW2K);
  115. BREAK_ON_FAILED_HRESULT(hr);
  116. if(valuesW2K.size()==0)
  117. {
  118. error=L"No values";
  119. hr=E_FAIL;
  120. break;
  121. }
  122. if (valuesW2K.size()!=1)
  123. {
  124. error=L"Size should be 1";
  125. hr=E_FAIL;
  126. break;
  127. }
  128. W2KValue=*valuesW2K.begin();
  129. }
  130. else
  131. {
  132. // type == REPLACE_W2K_MULTIPLE_VALUE
  133. String sW2KXP(value+2); // +2 for index and comma
  134. StringList lW2KXP;
  135. size_t cnt=sW2KXP.tokenize(back_inserter(lW2KXP),L";");
  136. if(cnt!=2)
  137. {
  138. error=L"There should be two strings (W2K and XP)";
  139. hr=E_FAIL;
  140. break;
  141. }
  142. hr=csvIntlW2K.getCsvValue(
  143. locale,
  144. object,
  145. property,
  146. lW2KXP.begin()->c_str(),
  147. W2KValue
  148. );
  149. BREAK_ON_FAILED_HRESULT(hr);
  150. if(W2KValue.size()==0)
  151. {
  152. error=L"Did not find value(s)",L"Error";
  153. hr=E_FAIL;
  154. break;
  155. }
  156. size_t pos=W2KValue.find(L',');
  157. if(pos==String::npos)
  158. {
  159. error=L"MultipleValue without comma",L"Error";
  160. hr=E_FAIL;
  161. break;
  162. }
  163. }
  164. // by now the W2KValue is loaded
  165. // The test sequence
  166. // This test sequence is usefull when you already have
  167. // replaceW2KStrs from a previous run and you want to
  168. // test that the strings have been correctly
  169. // retrieved, encoded and decoded
  170. //pair<long,long> tmpIndxLoc;
  171. //tmpIndxLoc.first=index;
  172. //tmpIndxLoc.second=locale;
  173. //String tmpValue=replaceW2KStrs[tmpIndxLoc];
  174. //if (tmpValue!=W2KValue)
  175. //{
  176. //hr=E_FAIL;
  177. //break;
  178. //}
  179. long index = *value;
  180. hr=FS::WriteLine(file,
  181. String::format(L"tmpIndxLoc.first=%1!d!;",index));
  182. BREAK_ON_FAILED_HRESULT(hr);
  183. hr=FS::WriteLine(file,
  184. String::format(L"tmpIndxLoc.second=0x%1!3x!;",locale));
  185. BREAK_ON_FAILED_HRESULT(hr);
  186. hr=FS::Write
  187. (
  188. file,
  189. String::format
  190. (
  191. L"replaceW2KStrs[tmpIndxLoc]=L\"%1\";\r\n",
  192. escape( W2KValue.c_str() ).c_str()
  193. )
  194. );
  195. BREAK_ON_FAILED_HRESULT(hr);
  196. } // if(changes[c].change== is REPLACE multiple or single
  197. } // for c (for each change in the entry)
  198. BREAK_ON_FAILED_HRESULT(hr);
  199. }// for i (for each entry in the change list)
  200. BREAK_ON_FAILED_HRESULT(hr);
  201. }// for l (for each locale)
  202. BREAK_ON_FAILED_HRESULT(hr);
  203. } while(0);
  204. CloseHandle(file);
  205. if (FAILED(hr))
  206. {
  207. MessageBox(NULL,L"Problems during generation",L"Error",MB_OK);
  208. }
  209. else
  210. {
  211. MessageBox(NULL,L"Generation Successfull",L"Success",MB_OK);
  212. }
  213. LOG_HRESULT(hr);
  214. return 1;
  215. }