/****************************** Module Header ******************************\ * Module Name: jpn.c * * Copyright (c) 1985 - 1999, Microsoft Corporation * * FEMGRATE, JPN speciific functions * \***************************************************************************/ #include "femgrate.h" #include BOOL FixSpecificFolder(HINF hInf) { BOOL bRet = FALSE; INFCONTEXT InfContext; UINT LineCount,LineNo; LPCTSTR szSectionName = TEXT("Folder.SpecificObjectToRename"); LPCTSTR RegName; LPCTSTR NT4Name; LPCTSTR NT5Name; LPCTSTR MoveIt; TCHAR szUSFRegKey[MAX_PATH]; TCHAR szNTUSF[MAX_PATH]; TCHAR szExpNT4USF[MAX_PATH]; TCHAR szExpNT5USF[MAX_PATH]; DWORD dwSize, dwType; LONG lResult; UINT uiCount; HKEY hKey; if(hInf == INVALID_HANDLE_VALUE) { DebugMsg((DM_VERBOSE,TEXT("[FixSpecificFolder] Open femgrate.inf failed !\n"))); return FALSE; } LineCount = (UINT)SetupGetLineCount(hInf,szSectionName); if((LONG)LineCount <= 0) { DebugMsg((DM_VERBOSE,TEXT("[FixSpecificFolder] line count == 0 !\n"))); goto err1; } for(LineNo=0; LineNo szFolder :\n%s\n"),szExpNT4USF)); RegCloseKey (hKey); continue; } // // MoveIt == 1, we want move it to new folder // else, we just update registry // if (lstrcmp(MoveIt,TEXT("1")) == 0) { ExpandEnvironmentStrings (NT4Name, szExpNT4USF, MAX_PATH); ExpandEnvironmentStrings (NT5Name, szExpNT5USF, MAX_PATH); if (CopyProfileDirectory (szExpNT4USF, szExpNT5USF, CPD_IGNOREHIVE)) { DebugMsg((DM_VERBOSE, TEXT("Fix Folder: Successfully changed folder name:\n%s\n%s"),szExpNT4USF,szExpNT5USF)); if (Delnode (szExpNT4USF)) { DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Successfully remove folder:\n%s\n"),szExpNT4USF)); } else { DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Failed remove folder:\n%s\n"),szExpNT4USF)); } } else { DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Failed to change folder name:\n%s\n%s"),szExpNT4USF,szExpNT5USF)); } } // // Set CSIDL_PERSONAL to point to this directory. // lResult = RegSetValueEx (hKey, szUSFRegKey, 0, REG_EXPAND_SZ, (LPBYTE) NT5Name, (lstrlen(NT5Name) + 1) * sizeof(TCHAR)); if (lResult != ERROR_SUCCESS) { DebugMsg((DM_VERBOSE, TEXT("[FixUserFolders] Set Registry faile, %s,%s\n"),szUSFRegKey,NT5Name)); } RegCloseKey (hKey); } } bRet = TRUE; err1: return bRet; } BOOL FixFoldersInSetup(HINF hInf,BOOL bCommonGroup) { BOOL bRet = FALSE; INFCONTEXT InfContext; UINT LineCount,LineNo; LPCTSTR szSectionName = TEXT("Folder.ObjectToRenameInSetup"); LPCTSTR RegName; LPCTSTR NT4Name; LPCTSTR NT5Name; TCHAR szUSFRegKey[MAX_PATH]; TCHAR szNT5USF[MAX_PATH]; TCHAR szNT4USF[MAX_PATH]; TCHAR szExpNT4USF[MAX_PATH]; TCHAR szExpNT5USF[MAX_PATH]; DWORD dwSize, dwType; LONG lResult; HKEY hKey; if(hInf == INVALID_HANDLE_VALUE) { DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] Open femgrate.inf failed !\n"))); return FALSE; } LineCount = (UINT)SetupGetLineCount(hInf,szSectionName); if((LONG)LineCount <= 0) { DebugMsg((DM_VERBOSE,TEXT("[FixFoldersInSetup] line count == 0 !\n"))); goto err1; } for(LineNo=0; LineNo nCommon) { lpTag = fd.cFileName + nFileName - nCommon; DebugMsg((DM_VERBOSE, TEXT("[FixCommon] lpTag=%s szCommon=%s\n"),lpTag, szCommon)); if (!lstrcmpi(lpTag, szCommon)) { lstrcpy (lpEnd, fd.cFileName); *lpTag = TEXT('\0'); lstrcpy (lpEnd2, fd.cFileName); if (CopyProfileDirectory (szExpProgramFolderPath, szProgramFolderPath, CPD_IGNOREHIVE)) { DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Successfully changed group name:\n"))); DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Orginial: %s\n"), szExpProgramFolderPath)); DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : New: %s\n"), szProgramFolderPath)); if (Delnode (szExpProgramFolderPath)) { DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Successfully remove folder:\n%s\n"),szExpProgramFolderPath)); } else { DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Failed remove folder:\n%s\n"),szExpProgramFolderPath)); } } else { DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Failed to change group name with error %d.\n"), GetLastError())); DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : Orginial: %s\n"), szExpProgramFolderPath)); DebugMsg((DM_VERBOSE, TEXT("[FixCommon] : New: %s\n"), szProgramFolderPath)); } } } } } while (FindNextFile(hFile, &fd)); FindClose (hFile); } bRet = TRUE; err1: return bRet; } BOOL RenameLink( BOOL bCommonGroup, LPCTSTR ObjSrcName, LPCTSTR ObjDstName, LPCTSTR ObjPath) { TCHAR szSrcPath[MAX_PATH]; TCHAR szDstPath[MAX_PATH]; LONG lResult; BOOL bRet=FALSE; DebugMsg((DM_VERBOSE,TEXT("[RenameLink] \nOld = %s\nNew = %s\nPath = %s\n"),ObjSrcName,ObjDstName,ObjPath)); if (!GetProgramsDirectory(bCommonGroup,szSrcPath)) return bRet; if ( !GetProgramsDirectory(bCommonGroup,szDstPath)) return bRet; if (ObjPath && *ObjPath) { ConcatenatePaths(szSrcPath,ObjPath,MAX_PATH); ConcatenatePaths(szDstPath,ObjPath,MAX_PATH); } ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH); ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH); lstrcat(szSrcPath,TEXT(".lnk")); lstrcat(szDstPath,TEXT(".lnk")); lResult = GetFileAttributes(szSrcPath); if (lResult == 0xFFFFFFFF) { // // Directory does not exist. // DebugMsg((DM_VERBOSE, TEXT("[RenameLink] File is not existed [%s] !\n"),szSrcPath)); goto err1; } if (lResult & FILE_ATTRIBUTE_DIRECTORY) { // // this is a directory, but we want a file. // DebugMsg((DM_VERBOSE, TEXT("[RenameLink] This is a directory [%s] !\n"),szSrcPath)); goto err1; } // // if destination file existed, it's not good ! // lResult = GetFileAttributes(szDstPath); if (lResult == 0xFFFFFFFF) { if (MoveFile (szSrcPath, szDstPath)) { DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Successfully changed link name:\n%s\n%s\n"),szSrcPath,szDstPath)); } else { DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Failed to change link name with error %d.\n%s\n%s\n"), GetLastError(),szSrcPath,szDstPath)); goto err1; } } else { DebugMsg((DM_VERBOSE, TEXT("[RenameLink] Destination file existed, maybe we don't want to overwrite ,%s\n"),szDstPath)); goto err1; } bRet = TRUE; err1: return bRet; } BOOL RenameFolder( BOOL bCommonGroup, LPCTSTR ObjSrcName, LPCTSTR ObjDstName) { TCHAR szSrcPath[MAX_PATH]; TCHAR szDstPath[MAX_PATH]; LONG lResult; BOOL bRet=FALSE; DebugMsg((DM_VERBOSE,TEXT("[RenameFolder]\nOld = %s\nNew = %s\n"),ObjSrcName,ObjDstName)); GetProgramsDirectory(bCommonGroup,szSrcPath); GetProgramsDirectory(bCommonGroup,szDstPath); ConcatenatePaths(szSrcPath,ObjSrcName,MAX_PATH); ConcatenatePaths(szDstPath,ObjDstName,MAX_PATH); lResult = GetFileAttributes(szSrcPath); if (lResult == 0xFFFFFFFF) { // // Directory does not exist. // DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Directory is not existed [%s] !\n"),szSrcPath)); goto err1; } if (!(lResult & FILE_ATTRIBUTE_DIRECTORY)) { // // this is not a directory. // DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] This is not a directory [%s] !\n"),szSrcPath)); goto err1; } if (CopyProfileDirectory (szSrcPath, szDstPath, CPD_IGNOREHIVE)) { DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Successfully changed folder name:\n%s\n%s"),szSrcPath,szDstPath)); if (! Delnode(szSrcPath)) { DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Delete old folder (%s) failed !"), szSrcPath)); } else { DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Delete old folder (%s) successfully !"), szSrcPath)); } } else { DebugMsg((DM_VERBOSE, TEXT("[RenameFolder] Convert Folder: Failed to change group name with error %d\n.%s\n%s\n"), GetLastError(),szSrcPath,szDstPath)); goto err1; } bRet = TRUE; err1: return bRet; } BOOL RenameProgramFolderOrLink(HINF hInf,BOOL bCommon) { BOOL bRet = FALSE; INFCONTEXT InfContext; UINT LineCount,LineNo; LPCTSTR szSectionName = TEXT("StartMenu.ObjectToRename"); LPCTSTR ObjectType; LPCTSTR ObjectSrcName; LPCTSTR ObjectDstName; LPCTSTR ObjectPath; LPCTSTR GroupAttribute; BOOL CommonGroup; BOOL IsMenuItem; if(hInf == INVALID_HANDLE_VALUE) { DebugMsg((DM_VERBOSE,TEXT("FEGRPCV: Open femgrate.inf failed !\n"))); return FALSE; } LineCount = (UINT)SetupGetLineCount(hInf,szSectionName); if((LONG)LineCount <= 0) { goto err1; } for(LineNo=0; LineNo