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.

256 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. photosII.c
  5. Abstract:
  6. This source file implements the operations needed to properly migrate MGI PhotoSuite II 1.0 from
  7. Windows 9x to Windows NT. This is part of the Setup Migration DLL.
  8. Author:
  9. Calin Negreanu (calinn) 15-Jul-1999
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #include "setupmigp.h"
  14. #define S_MIGRATION_PATHS "Migration Paths"
  15. #define S_PHOTOSII_FILE1 "PhotoSuite.EXE"
  16. #define S_PHOTOSII_FILE2 "W_Welcome.html"
  17. #define S_PHOTOSII_RELPATH1 "\\TempPSII\\Common\\"
  18. #define S_PHOTOSII_RELPATH2 "\\TempPSII\\Photos\\"
  19. #define MEMDB_CATEGORY_PHOTOSII "PhotoSuiteII"
  20. #define S_COMPANYNAME "CompanyName"
  21. #define S_PRODUCTVER "ProductVersion"
  22. #define S_PHOTOSII_COMPANYNAME "MGI Software*"
  23. #define S_PHOTOSII_PRODUCTVER "1.0*"
  24. static GROWBUFFER g_FilesBuff = GROWBUF_INIT;
  25. BOOL
  26. PhotoSuiteII_Attach (
  27. IN HINSTANCE DllInstance
  28. )
  29. {
  30. return TRUE;
  31. }
  32. BOOL
  33. PhotoSuiteII_Detach (
  34. IN HINSTANCE DllInstance
  35. )
  36. {
  37. FreeGrowBuffer (&g_FilesBuff);
  38. return TRUE;
  39. }
  40. LONG
  41. PhotoSuiteII_QueryVersion (
  42. IN PCSTR *ExeNamesBuf
  43. )
  44. {
  45. HKEY key = NULL;
  46. PCTSTR fullFileName = NULL;
  47. PCTSTR fileName = NULL;
  48. DWORD result = ERROR_SUCCESS;
  49. MultiSzAppendA (&g_FilesBuff, S_PHOTOSII_FILE1);
  50. *ExeNamesBuf = g_FilesBuff.Buf;
  51. return result;
  52. }
  53. LONG
  54. PhotoSuiteII_Initialize9x (
  55. IN PCSTR WorkingDirectory,
  56. IN PCSTR SourceDirectories
  57. )
  58. {
  59. INFSTRUCT context = INITINFSTRUCT_GROWBUFFER;
  60. PCSTR fullFileName = NULL;
  61. PCSTR fileName = NULL;
  62. PCSTR companyName = NULL;
  63. PCSTR productVer = NULL;
  64. LONG result = ERROR_NOT_INSTALLED;
  65. //
  66. // Let's find out where are our files located
  67. //
  68. if (g_MigrateInf != INVALID_HANDLE_VALUE) {
  69. if (InfFindFirstLineA (g_MigrateInf, S_MIGRATION_PATHS, NULL, &context)) {
  70. do {
  71. fullFileName = InfGetStringFieldA (&context, 1);
  72. if (fullFileName) {
  73. __try {
  74. fileName = GetFileNameFromPathA (fullFileName);
  75. if (StringIMatchA (fileName, S_PHOTOSII_FILE1)) {
  76. companyName = QueryVersionEntry (fullFileName, S_COMPANYNAME);
  77. if ((!companyName) ||
  78. (!IsPatternMatchA (S_PHOTOSII_COMPANYNAME, companyName))
  79. ) {
  80. #pragma prefast(suppress:242, "Don't care about perf of try/finally here")
  81. continue;
  82. }
  83. productVer = QueryVersionEntry (fullFileName, S_PRODUCTVER);
  84. if ((!productVer) ||
  85. (!IsPatternMatchA (S_PHOTOSII_PRODUCTVER, productVer))
  86. ) {
  87. #pragma prefast(suppress:242, "Don't care about perf of try/finally here")
  88. continue;
  89. }
  90. result = ERROR_SUCCESS;
  91. MemDbSetValueExA (MEMDB_CATEGORY_PHOTOSII, fullFileName, NULL, NULL, 0, NULL);
  92. FreePathStringA (productVer);
  93. productVer = NULL;
  94. FreePathStringA (companyName);
  95. companyName = NULL;
  96. }
  97. }
  98. __finally {
  99. if (productVer) {
  100. FreePathStringA (productVer);
  101. productVer = NULL;
  102. }
  103. if (companyName) {
  104. FreePathStringA (companyName);
  105. companyName = NULL;
  106. }
  107. }
  108. }
  109. } while (InfFindNextLine (&context));
  110. InfCleanUpInfStruct (&context);
  111. }
  112. if (result == ERROR_NOT_INSTALLED) {
  113. DEBUGMSGA ((DBG_VERBOSE, "MGI PhotoSuite II migration DLL: Could not find needed files."));
  114. }
  115. } else {
  116. DEBUGMSGA ((DBG_ERROR, "MGI PhotoSuite II migration DLL: Could not open MIGRATE.INF."));
  117. }
  118. return result;
  119. }
  120. LONG
  121. PhotoSuiteII_MigrateUser9x (
  122. IN HWND ParentWnd,
  123. IN PCSTR UnattendFile,
  124. IN HKEY UserRegKey,
  125. IN PCSTR UserName
  126. )
  127. {
  128. return ERROR_SUCCESS;
  129. }
  130. LONG
  131. PhotoSuiteII_MigrateSystem9x (
  132. IN HWND ParentWnd,
  133. IN PCSTR UnattendFile
  134. )
  135. {
  136. return ERROR_SUCCESS;
  137. }
  138. LONG
  139. PhotoSuiteII_InitializeNT (
  140. IN PCWSTR WorkingDirectory,
  141. IN PCWSTR SourceDirectories
  142. )
  143. {
  144. return ERROR_SUCCESS;
  145. }
  146. LONG
  147. PhotoSuiteII_MigrateUserNT (
  148. IN HINF UnattendFile,
  149. IN HKEY UserRegKey,
  150. IN PCWSTR UserName
  151. )
  152. {
  153. return ERROR_SUCCESS;
  154. }
  155. LONG
  156. PhotoSuiteII_MigrateSystemNT (
  157. IN HINF UnattendFile
  158. )
  159. {
  160. MEMDB_ENUMA e;
  161. CHAR pattern[MEMDB_MAX];
  162. CHAR file1[MEMDB_MAX];
  163. CHAR file2[MEMDB_MAX];
  164. PSTR filePtr;
  165. UINT uiCharNum;
  166. MemDbBuildKeyA (pattern, MEMDB_CATEGORY_PHOTOSII, "*", NULL, NULL);
  167. if (MemDbEnumFirstValueA (&e, pattern, MEMDB_ALL_SUBLEVELS, MEMDB_ENDPOINTS_ONLY)) {
  168. do {
  169. //
  170. // we want to copy a file that is relative to this one
  171. //
  172. filePtr = _mbsrchr (e.szName, '\\');
  173. if (filePtr) {
  174. if((filePtr - e.szName + 1) >= ARRAYSIZE(file1)){
  175. MYASSERT(FALSE);
  176. LOG((LOG_WARNING, "PhotoSuiteII_MigrateSystemNT does not provide enough buffer for string copy %s -- skipping CopyFile", e.szName));
  177. continue;
  178. }
  179. StringCopyABA (file1, e.szName, filePtr);
  180. uiCharNum = strlen(file1);
  181. } else {
  182. uiCharNum = strlen(e.szName);
  183. if(uiCharNum >= ARRAYSIZE(file1)){
  184. MYASSERT(FALSE);
  185. LOG((LOG_WARNING, "PhotoSuiteII_MigrateSystemNT does not provide enough buffer for string copy %s -- skipping CopyFile", e.szName));
  186. #pragma prefast(suppress:242, "Don't care about perf of try/finally here")
  187. continue;
  188. }
  189. StackStringCopyA (file1, e.szName);
  190. }
  191. StringCopyA (file2, file1);
  192. if((uiCharNum + ARRAYSIZE(S_PHOTOSII_RELPATH1) + ARRAYSIZE(S_PHOTOSII_FILE2) - 2) >= ARRAYSIZE(file1) ||
  193. (uiCharNum + ARRAYSIZE(S_PHOTOSII_RELPATH2) + ARRAYSIZE(S_PHOTOSII_FILE2) - 2) >= ARRAYSIZE(file2)){
  194. MYASSERT(FALSE);
  195. LOG((LOG_WARNING, "PhotoSuiteII_MigrateSystemNT does not provide enough buffer for string copy %s -- skipping CopyFile", e.szName));
  196. continue;
  197. }
  198. StringCatA (file1, S_PHOTOSII_RELPATH1);
  199. StringCatA (file2, S_PHOTOSII_RELPATH2);
  200. StringCatA (file1, S_PHOTOSII_FILE2);
  201. StringCatA (file2, S_PHOTOSII_FILE2);
  202. if (!CopyFile (file1, file2, TRUE)) {
  203. DEBUGMSGA ((
  204. DBG_ERROR,
  205. "MGI PhotoSuite II migration DLL: Could not copy %s to %s. Error:%d",
  206. file1,
  207. file2,
  208. GetLastError ()
  209. ));
  210. }
  211. } while (MemDbEnumNextValueA (&e));
  212. }
  213. return ERROR_SUCCESS;
  214. }