Пример #1
0
//////////////////////////////////////////////////////////
//
// CInstallManager::_ProcessLayoutChecks
//
// Make sure new reg/dir structure is ok
//
//////////////////////////////////////////////////////////
SString CInstallManager::_ProcessLayoutChecks ( void )
{
    //
    // Validation
    //

    // Check data dir exists
    {
        if ( !DirectoryExists ( GetMTADataPath () ) )
            ShowLayoutError ( "[Data directory not present]" );   // Can't find directory
    }

    // Check reg key exists
    //{
    //    if ( GetRegistryValue ( "", "Last Install Location" ).empty () )
    //        ShowLayoutError ( "[Registry key not present]" );   // Can't find reg key
    //}

    // Check data dir writable
    {
        SString strTestFilePath = PathJoin ( GetMTADataPath (), "testdir", "testfile.txt" );

        FileDelete ( strTestFilePath );
        RemoveDirectory ( ExtractPath ( strTestFilePath ) );

        SString strContent = "test";
        if ( !FileSave ( strTestFilePath, strContent ) )
            ShowLayoutError ( "[Data directory not writable]" );   // Can't save file

        FileDelete ( strTestFilePath );
        RemoveDirectory ( ExtractPath ( strTestFilePath ) );
    }

    // Check reg key writable
    {
        RemoveRegistryKey ( "testkeypath" );

        SString strValue = GetTimeString( true, true );
        SetRegistryValue ( "testkeypath", "testname", strValue );
        SString strValueCheck = GetRegistryValue ( "testkeypath", "testname" );
        if ( strValueCheck != strValue )
            ShowLayoutError ( "[Registry key not writable]" );   // Can't write reg key

        RemoveRegistryKey ( "testkeypath" );
    }

    // Check install dir writable
    {
        SString strTestFilePath = CalcMTASAPath ( PathJoin ( "mta", "writetest.txt" ) );

        FileDelete ( strTestFilePath );

        SString strContent = "test";
        if ( !FileSave ( strTestFilePath, strContent ) )
            ShowLayoutError ( "[Install directory not writable]" );   // Can't save file

        FileDelete ( strTestFilePath );
    }

    //
    // Migration
    //

    // If news/temp/upcache folder doesn't exist in new, but does in old place, move it
    {
        const char* folders[] = { "news", "temp", "upcache" };
        for ( uint i = 0 ; i < NUMELMS( folders ) ; i++ )
        {
            SString strSrc = PathJoin ( GetSystemLocalAppDataPath (), "MTA San Andreas " + GetMajorVersionString (), folders[i] );
            SString strDest = PathJoin ( GetMTADataPath (), folders[i] );
            if ( !DirectoryExists ( strDest ) && DirectoryExists ( strSrc ) )
                MoveFile ( strSrc, strDest );
        }
    }

    // If aero option reg entry doesn't exist in new, but does in old place, move it
    {
        if ( GetApplicationSetting ( "aero-enabled" ).empty () )
        {
            SString strLegacyValue = GetVersionRegistryValueLegacy ( GetMajorVersionString (), PathJoin ( "Settings", "general" ), "aero-enabled" );
            if ( !strLegacyValue.empty () )
                SetApplicationSettingInt ( "aero-enabled", atoi ( strLegacyValue ) );
            else
                SetApplicationSettingInt ( "aero-enabled", 1 );
        }
    }

    return "ok";
}
Пример #2
0
// Delete a setting key
bool SharedUtil::RemoveApplicationSettingKey ( const SString& strPath )
{
    return RemoveRegistryKey ( PathJoin ( "Settings", strPath ) );
}