Leaked source code of windows server 2003
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.

164 lines
4.5 KiB

  1. #include <windows.h>
  2. #include <shellapi.h>
  3. #include <string.h>
  4. #include "resource.h"
  5. //---------------------------------------------------------------------------
  6. // appwide globals
  7. char g_szCurrentDir[MAX_PATH];
  8. char g_szCodePage[32];
  9. //---------------------------------------------------------------------------
  10. BOOL _PathRemoveFileSpec(LPSTR pFile)
  11. {
  12. LPSTR pT;
  13. LPSTR pT2 = pFile;
  14. for (pT = pT2; *pT2; pT2 = CharNext(pT2)) {
  15. if (*pT2 == '\\')
  16. pT = pT2; // last "\" found, (we will strip here)
  17. else if (*pT2 == ':') { // skip ":\" so we don't
  18. if (pT2[1] =='\\') // strip the "\" from "C:\"
  19. pT2++;
  20. pT = pT2 + 1;
  21. }
  22. }
  23. if (*pT == 0)
  24. return FALSE; // didn't strip anything
  25. //
  26. // handle the \foo case
  27. //
  28. else if ((pT == pFile) && (*pT == '\\')) {
  29. // Is it just a '\'?
  30. if (*(pT+1) != '\0') {
  31. // Nope.
  32. *(pT+1) = '\0';
  33. return TRUE; // stripped something
  34. }
  35. else {
  36. // Yep.
  37. return FALSE;
  38. }
  39. }
  40. else {
  41. *pT = 0;
  42. return TRUE; // stripped something
  43. }
  44. }
  45. //---------------------------------------------------------------------------
  46. void ExecuteAutorun()
  47. {
  48. char szIniPath[MAX_PATH];
  49. char szTmpPath[MAX_PATH];
  50. char szAutorunApp[MAX_PATH];
  51. char szDir[MAX_PATH];
  52. char szLang[8];
  53. BOOL fExecuted = FALSE;
  54. lstrcpy( szTmpPath, g_szCurrentDir );
  55. lstrcat( szTmpPath, "\\locale.ini" );
  56. GetTempPath( MAX_PATH, szIniPath );
  57. lstrcat( szIniPath, "locale.ini" );
  58. CopyFile( szTmpPath, szIniPath, FALSE );
  59. SetFileAttributes( szIniPath, FILE_ATTRIBUTE_NORMAL );
  60. if (GetPrivateProfileString("Locale", g_szCodePage, "", szLang, sizeof(szLang), szIniPath))
  61. {
  62. lstrcpy( szDir, g_szCurrentDir );
  63. lstrcat( szDir, szLang );
  64. lstrcat( szDir, TEXT("bin\\") );
  65. lstrcpy( szAutorunApp, szDir );
  66. lstrcat( szAutorunApp, "IECD.exe" );
  67. if (GetFileAttributes(szAutorunApp) != 0xFFFFFFFF)
  68. {
  69. ShellExecute( NULL, NULL, szAutorunApp, " ", szDir, SW_SHOWNORMAL );
  70. fExecuted = TRUE;
  71. }
  72. }
  73. if( !fExecuted )
  74. {
  75. GetPrivateProfileString( "Locale", "Default", "\\EN\\", szLang, sizeof(szLang), szIniPath );
  76. lstrcpy( szDir, g_szCurrentDir );
  77. lstrcat( szDir, szLang );
  78. lstrcat( szDir, TEXT("bin\\") );
  79. lstrcpy( szAutorunApp, szDir );
  80. lstrcat( szAutorunApp, "IECD.exe" );
  81. ShellExecute( NULL, NULL, szAutorunApp, " ", szDir, SW_SHOWNORMAL );
  82. }
  83. }
  84. //---------------------------------------------------------------------------
  85. void GetCodePage( )
  86. {
  87. DWORD dwLCID;
  88. dwLCID = GetSystemDefaultLCID();
  89. if (dwLCID > 0x00000FFF)
  90. wsprintf(g_szCodePage, "0000%x", dwLCID);
  91. else
  92. wsprintf(g_szCodePage, "00000%x", dwLCID);
  93. }
  94. //---------------------------------------------------------------------------
  95. int _stdcall ModuleEntry(void)
  96. {
  97. int i;
  98. STARTUPINFO si;
  99. LPSTR pszCmdLine = GetCommandLine();
  100. if ( *pszCmdLine == '\"' ) {
  101. /*
  102. * Scan, and skip over, subsequent characters until
  103. * another double-quote or a null is encountered.
  104. */
  105. while ( *++pszCmdLine && (*pszCmdLine != '\"') )
  106. ;
  107. /*
  108. * If we stopped on a double-quote (usual case), skip
  109. * over it.
  110. */
  111. if ( *pszCmdLine == '\"' )
  112. pszCmdLine++;
  113. }
  114. else {
  115. while (*pszCmdLine > ' ')
  116. pszCmdLine++;
  117. }
  118. /*
  119. * Skip past any white space preceeding the second token.
  120. */
  121. while (*pszCmdLine && (*pszCmdLine <= ' ')) {
  122. pszCmdLine++;
  123. }
  124. si.dwFlags = 0;
  125. GetStartupInfoA(&si);
  126. i = WinMain(GetModuleHandle(NULL), NULL, pszCmdLine,
  127. si.dwFlags & STARTF_USESHOWWINDOW ? si.wShowWindow : SW_SHOWDEFAULT);
  128. ExitProcess(i);
  129. return i; // We never comes here.
  130. }
  131. //---------------------------------------------------------------------------
  132. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  133. {
  134. GetModuleFileName(NULL, g_szCurrentDir, sizeof(g_szCurrentDir));
  135. _PathRemoveFileSpec(g_szCurrentDir);
  136. if (lstrlen(g_szCurrentDir) == 3)
  137. g_szCurrentDir[2] = '\0';
  138. GetCodePage();
  139. ExecuteAutorun();
  140. return 0;
  141. }