size_t GetSystemDir( char *buff, size_t buff_len ) /************************************************/ { // inst PRFPROFILE prof; size_t i; prof.cchUserName = 0L; prof.cchSysName = 0L; i = 0; if( PrfQueryProfile( GUIGetHAB(), &prof ) ) { if( prof.cchSysName > 0 ) { _AllocA( prof.pszSysName, prof.cchSysName ); _AllocA( prof.pszUserName, prof.cchUserName ); PrfQueryProfile( GUIGetHAB(), &prof ); } if( buff_len > prof.cchSysName ) buff_len = prof.cchSysName; memcpy( buff, prof.pszSysName, buff_len ); if( buff_len > 0 ) i = --buff_len; // reserve space for terminating null character while( i > 0 ) { if( buff[--i] == '\\' ) { break; } } } buff[i] = NULLCHAR; return( strlen( buff ) ); } /* _wpi_getinidirectory */
unsigned GetSystemDir( char *buff, int max ) /***********************************************/ { // inst PRFPROFILE prof; int i; char c; int len; prof.cchUserName = 0L; prof.cchSysName = 0L; if( PrfQueryProfile( GUIGetHAB(), &prof ) ) { if( prof.cchSysName > 0 ) { _AllocA( prof.pszSysName, prof.cchSysName ); _AllocA( prof.pszUserName, prof.cchUserName ); PrfQueryProfile( GUIGetHAB(), &prof ); } strcpy( buff, prof.pszSysName ); if( prof.cchSysName <= max ) { len = prof.cchSysName; } else { len = max; } for( i = len - 1; i >= 0; i-- ) { c = buff[i]; buff[i] = '\0'; if( c == '\\' ) { break; } } } else { buff[0] = '\0'; } return( strlen( buff ) ); } /* _wpi_getinidirectory */
BOOL RecoverProfile(HINI hProfile) { HINI hDestProfile; HINI hSourceProfile; APIRET rc; char szTempFile[40]; char *pIniFile; PRFPROFILE stProfileNames; stProfileNames.cchUserName = 0; stProfileNames.cchSysName = 0; PrfQueryProfile(habAnchorBlock,&stProfileNames); stProfileNames.pszUserName = malloc(stProfileNames.cchUserName + 1); stProfileNames.pszSysName = malloc(stProfileNames.cchSysName + 1); PrfQueryProfile(habAnchorBlock,&stProfileNames); if (hProfile == HINI_USERPROFILE) strcpy(szTempFile,"C:\\OS2\\DLL\\_USER_.INI"); else strcpy(szTempFile,"C:\\OS2\\DLL\\_SYSTEM_.INI"); if ((hDestProfile = PrfOpenProfile(habAnchorBlock,szTempFile)) != 0) { if (CopyProfile(hProfile,hDestProfile)) { if (PrfCloseProfile(hDestProfile)) { if (hProfile == HINI_USERPROFILE) { pIniFile = stProfileNames.pszUserName; stProfileNames.pszUserName = szTempFile; stProfileNames.cchUserName = sizeof(szTempFile); } else { pIniFile = stProfileNames.pszSysName; stProfileNames.pszSysName = szTempFile; stProfileNames.cchSysName = sizeof(szTempFile); } if (PrfReset(habAnchorBlock,&stProfileNames)) { DosCopy(szTempFile,pIniFile,DCPY_EXISTING); if (hProfile == HINI_USERPROFILE) { stProfileNames.pszUserName = pIniFile; stProfileNames.cchUserName = sizeof(pIniFile); } else { stProfileNames.pszSysName = pIniFile; stProfileNames.cchSysName = sizeof(pIniFile); } if (PrfReset(habAnchorBlock,&stProfileNames)) DosDelete(szTempFile); } } } else PrfCloseProfile(hDestProfile); } free(stProfileNames.pszUserName); free(stProfileNames.pszSysName); PrintString("Profile Recovery Complete",5); return(TRUE); }
unsigned long SysIni(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { HINI hini; unsigned long x; unsigned long len; unsigned long lSize; char *IniFile = ""; char *App; char *Key = ""; char *Val; char Temp[256]; char UserName[256]; char SysName[256]; PRFPROFILE PrfInfo; long Error = FALSE; bool WildCard = FALSE; bool QueryApps; RXSTEMDATA ldp; // initialize PM HAB AnchBlk = NULLHANDLE; bool WinIntial = TRUE; #ifdef DLOGGING logmessage(__func__); #endif /* validate arguments */ if (numargs < 2 || numargs > 4 || !RXVALIDSTRING(args[1])) return INVALID_ROUTINE; /* get pointers to args */ IniFile = args[0].strptr; App = args[1].strptr; if (numargs >= 3 && args[2].strptr) Key = args[2].strptr; if (numargs == 4) Val = args[3].strptr; /* Check KEY and APP values for "WildCard" */ if (!stricmp(App, "ALL:")) { App = ""; QueryApps = TRUE; WildCard = TRUE; if (numargs != 3) return INVALID_ROUTINE; /* Error - Not enough args */ else x = 2; /* Arg number of STEM variable*/ } else if (!stricmp(Key, "ALL:")) { Key = ""; Val = ""; QueryApps = FALSE; WildCard = TRUE; if (numargs != 4) return INVALID_ROUTINE; /* Error - Not enough args */ else x = 3; /* Arg number of STEM variable*/ } /* * If this is a "WildCard search, then allocate mem * for stem struct and get the stem name */ if (WildCard == TRUE) { ldp.count = 0; /* get the stem variable name */ strcpy(ldp.varname, args[x].strptr); ldp.stemlen = args[x].strlength; strupr(ldp.varname); /* uppercase the name */ if (ldp.varname[ldp.stemlen-1] != '.') ldp.varname[ldp.stemlen++] = '.'; } WININIT(WinIntial,AnchBlk) /************************************************************** * The following section of code gets the INI file handle * * given the INI file spec (IniFile). * * * * Possible Ini file specs: * * * * NULL - Same as USERPROFILE ( OS2.INI ) * * "BOTH" - Same as PROFILE ( OS2.INI & OS2SYS.INI ) * * "USER" - Same as USERPROFILE ( OS2.INI ) * * "SYSTEM" - Same as SYSTEMPROFILE ( OS2SYS.INI) * * other - Filespec of INI file. * **************************************************************/ hini = NULLHANDLE; if (!IniFile) hini = HINI_USERPROFILE; else if (!stricmp(IniFile, "BOTH")) hini = HINI_PROFILE; else if (!stricmp(IniFile, "USER")) hini = HINI_USERPROFILE; else if (!stricmp(IniFile, "SYSTEM")) hini = HINI_SYSTEMPROFILE; /*********************************************************** * If Ini file spec is 'other' then make sure it does not * * specify the current USER or SYSTEM profiles. * * * * Trying to open the current USER or SYSTEM ini file via * * PrfOpenProfile() will fail. Therefore, use the function * * PrfQueryProfile() to query the current USER and SYSTEM * * ini file specs. If the IniFile string matches either * * the current USER or SYSTEM file specs, then use either * * HINI_USERPROFILE or HINI_SYSTEMPROFILE as appropriate. * * * * If IniFile does not specify the current USER or SYSTEM * * ini file then use PrfOpenProfile() to get the ini file * * handle. * ***********************************************************/ else { PrfInfo.pszUserName = UserName; PrfInfo.cchUserName = sizeof(UserName); PrfInfo.pszSysName = SysName; PrfInfo.cchSysName = sizeof(SysName); if (PrfQueryProfile(AnchBlk, &PrfInfo)) { if (!stricmp(IniFile, PrfInfo.pszUserName)) hini = HINI_USERPROFILE; else if (!stricmp(IniFile, PrfInfo.pszSysName)) hini = HINI_SYSTEMPROFILE; else hini = PrfOpenProfile(AnchBlk, IniFile); } else hini = PrfOpenProfile(AnchBlk, IniFile); /************************************************** * Exit with INI FILE error if the ini file handle * * is NULL at this point (and if IniFile != BOTH, * * as that would make the handle NULL also). * **************************************************/ if (hini == NULLHANDLE && stricmp(IniFile, "BOTH")) { BUILDRXSTRING(retstr, ERROR_RETSTR); WINTERM(WinIntial,AnchBlk) return VALID_ROUTINE; } }
SOM_Scope BOOL SOMLINK WPSamFolder_RootDesktop (WPSamF *somSelf) { static PRFPROFILE prfProfile; PCHAR szUserIni; PCHAR szSysIni; /* WPSamFData *somThis = WPSamFGetData(somSelf); */ WPSamFMethodDebug ("WPSamF","WPSamFolder_RootDesktop"); /** Untersuchung, ob bereits im Rootdesktop **/ /* Namen der laufenden User- und System-INI-Dateien */ prfProfile.cchUserName = 0L; prfProfile.cchSysName = 0L; PrfQueryProfile (WinQueryAnchorBlock(HWND_DESKTOP), &prfProfile); prfProfile.pszUserName = malloc (prfProfile.cchUserName); prfProfile.pszSysName = malloc (prfProfile.cchSysName); PrfQueryProfile (WinQueryAnchorBlock(HWND_DESKTOP), &prfProfile); DebugE (D_SWT, "RootDesktop (current user-INI)", prfProfile.pszUserName); DebugE (D_SWT, "RootDesktop (current system-INI)", prfProfile.pszSysName); /* Namen der Stammprofile */ if (pShareInitOS2) { szUserIni = pShareInitOS2->pszRootUserIni; szSysIni = pShareInitOS2->pszRootSystemIni; } else szUserIni = szSysIni = ""; if (szUserIni[0] == '\0') if (DosScanEnv(USER_INI, &szUserIni)) goto root_false; if (szSysIni[0] == '\0') if (DosScanEnv (SYSTEM_INI, &szSysIni)) goto root_false; /* Vergleich der User-Ini Namen */ if (strcmpi (szUserIni, prfProfile.pszUserName) == 0) { WinAlarm (HWND_DESKTOP, WA_NOTE); MessageBox (IDS_ALREADYINROOT, IDS_INFORMATION, MB_ENTER | MB_INFORMATION); goto root_false; } free (prfProfile.pszUserName); free (prfProfile.pszSysName); /** Umschaltung **/ if (hevSammy) { pShareInitOS2->pszEnvironment[0] = '\0'; pShareInitOS2->pszEnvironment[1] = '\0'; pShareInitOS2->pszSystemIni[0] = '\0'; pShareInitOS2->pszUserIni[0] = '\0'; DebugE (D_SWT, "RootDesktop", "Ab hier macht Sammy weiter"); DosPostEventSem (hevSammy); } return TRUE; root_false: free (prfProfile.pszUserName); free (prfProfile.pszSysName); return FALSE; }