Any tips on saving information on the player's PC?
  • stefstef April 2010
    Hi

    Could someone offer me some tips on saving information on the player's PC without the player being able to find it . something really simple would be better


    I was thinking about trying to save something in the registry.
    Is it possible to save information in the registery from hge?


    Stev
  • anpdanpd April 2010
    The problem with saving now days is Vista you canґt write to ProgramFiles. But here is how I do it works for all versions of Windows I tried. It saves to a hidden folder so the user wonґt be able to find it without looking carefully. This also works even if not running as administator and will be carried over to other users on the computer.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    //Create save folder with full permission for all users 
    SHGetFolderPath( NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, strPath );
    PathAppend( strPath, TEXT( "Caelum" ));
     
    if( !PathFileExists( strPath ) )
    {
    if( ERROR_SUCCESS != SHCreateDirectoryEx( NULL, strPath, NULL ) )
    exit(0);
    }
     
    GiveDirectoryUserFullAccess(strPath);
     
    PathAppend( strPath, TEXT( "save.cpf" ) );
     
    bool GiveDirectoryUserFullAccess(LPCTSTR lpPath)
    {
    HANDLE hDir = CreateFile(lpPath,READ_CONTROL|WRITE_DAC,0,NULL,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,NULL);
    if(hDir == INVALID_HANDLE_VALUE) return false;
     
    ACL* pOldDACL=NULL;
    PSECURITY_DESCRIPTOR* pSD = NULL;
    GetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,&pOldDACL,NULL,pSD);
     
    EXPLICIT_ACCESS ea={0};
    ea.grfAccessMode = GRANT_ACCESS;
    ea.grfAccessPermissions = GENERIC_ALL;
    ea.grfInheritance = CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE;
    ea.Trustee.TrusteeType = TRUSTEE_IS_GROUP;
    ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
    ea.Trustee.ptstrName = TEXT("Users");
     
    ACL* pNewDACL = NULL;
    SetEntriesInAcl(1,&ea,pOldDACL,&pNewDACL);
     
    SetSecurityInfo(hDir,SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,pNewDACL,NULL);
     
    LocalFree(pSD);
    LocalFree(pNewDACL);
    CloseHandle(hDir);
    return true;
    }
    [/url]
  • stefstef April 2010
    thank you very much.

    I really appreciate it. That's probably the most i've received in 2 years.

    It just so happens that I have a windows vista machine.

    Question: On Vista, would it even ask me for permission to save/write ? Or will it simply not allow me to save/write ?

    Question: By the way, what are all the includes you used? I'm tracking them down. So far I have added .


    #include <windows>
    #include <AccCtrl>
    #include <Aclapi>
    #include <Shlobj>

    At this time the compiler doesn't recognize SHGFP_TYPE_CURRENT

    Thanks again
    Stephen
  • anpdanpd April 2010
    No problem glad I can help, had trouble finding the info myself :) you need to link to Shlwapi.lib and the headers are. With this it doesnґt ask you it just saves. If you try to save to ProgramFiles it doesnґt ask it just doesnґt work. You shouldnґt post this in this forum though this is for showcasing.

    #include <windows>
    #include <shlobj>
    #include <Shlwapi>
    #include <aclapi>

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion

Who's Online (0)