Implement GetFileDetails.

This commit is contained in:
Mr_Goldberg 2021-09-19 01:07:19 -04:00
parent acebfc4e4d
commit c8092f9f45
No known key found for this signature in database
GPG key ID: 8597D87419DEF278
5 changed files with 391 additions and 29 deletions

View file

@ -256,6 +256,39 @@ std::string canonical_path(std::string path)
return output;
}
bool file_exists_(std::string full_path)
{
#if defined(STEAM_WIN32)
struct _stat buffer;
if (_wstat(utf8_decode(full_path).c_str(), &buffer) != 0)
return false;
if ( buffer.st_mode & _S_IFDIR)
return false;
#else
struct stat buffer;
if (stat(full_path.c_str(), &buffer) != 0)
return false;
if (S_ISDIR(buffer.st_mode))
return false;
#endif
return true;
}
unsigned int file_size_(std::string full_path)
{
#if defined(STEAM_WIN32)
struct _stat buffer = {};
if (_wstat(utf8_decode(full_path).c_str(), &buffer) != 0) return 0;
#else
struct stat buffer = {};
if (stat (full_path.c_str(), &buffer) != 0) return 0;
#endif
return buffer.st_size;
}
static void steam_auth_ticket_callback(void *object, Common_Message *msg)
{
PRINT_DEBUG("steam_auth_ticket_callback\n");

View file

@ -101,6 +101,8 @@ std::string get_full_lib_path();
std::string get_full_program_path();
std::string get_current_path();
std::string canonical_path(std::string path);
bool file_exists_(std::string full_path);
unsigned int file_size_(std::string full_path);
#define DEFAULT_CB_TIMEOUT 0.002

View file

@ -607,24 +607,7 @@ bool Local_Storage::file_exists(std::string folder, std::string file)
}
std::string full_path = save_directory + appid + folder + file;
#if defined(STEAM_WIN32)
struct _stat buffer;
if (_wstat(utf8_decode(full_path).c_str(), &buffer) != 0)
return false;
if ( buffer.st_mode & _S_IFDIR)
return false;
#else
struct stat buffer;
if (stat(full_path.c_str(), &buffer) != 0)
return false;
if (S_ISDIR(buffer.st_mode))
return false;
#endif
return true;
return file_exists_(full_path);
}
unsigned int Local_Storage::file_size(std::string folder, std::string file)
@ -635,15 +618,7 @@ unsigned int Local_Storage::file_size(std::string folder, std::string file)
}
std::string full_path = save_directory + appid + folder + file;
#if defined(STEAM_WIN32)
struct _stat buffer = {};
if (_wstat(utf8_decode(full_path).c_str(), &buffer) != 0) return 0;
#else
struct stat buffer = {};
if (stat (full_path.c_str(), &buffer) != 0) return 0;
#endif
return buffer.st_size;
return file_size_(full_path);
}
bool Local_Storage::file_delete(std::string folder, std::string file)

View file

@ -16,6 +16,7 @@
<http://www.gnu.org/licenses/>. */
#include "steam_apps.h"
#include "../sha/sha1.hpp"
Steam_Apps::Steam_Apps(Settings *settings, class SteamCallResults *callback_results)
{
@ -201,6 +202,7 @@ uint32 Steam_Apps::GetInstalledDepots( DepotId_t *pvecDepots, uint32 cMaxDepots
uint32 Steam_Apps::GetAppInstallDir( AppId_t appID, char *pchFolder, uint32 cchFolderBufferSize )
{
PRINT_DEBUG("GetAppInstallDir %u %p %u\n", appID, pchFolder, cchFolderBufferSize);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
//TODO return real path instead of dll path
std::string installed_path = settings->getAppInstallPath(appID);
@ -279,8 +281,23 @@ void Steam_Apps::RequestAllProofOfPurchaseKeys()
STEAM_CALL_RESULT( FileDetailsResult_t )
SteamAPICall_t Steam_Apps::GetFileDetails( const char* pszFileName )
{
PRINT_DEBUG("GetFileDetails\n");
return 0;
PRINT_DEBUG("GetFileDetails %s\n", pszFileName);
FileDetailsResult_t data = {};
//TODO? this function should only return found if file is actually part of the steam depots
if (file_exists_(pszFileName)) {
data.m_eResult = k_EResultOK; //
std::ifstream stream(utf8_decode(pszFileName), std::ios::binary);
SHA1 checksum;
checksum.update(stream);
checksum.final().copy((char *)data.m_FileSHA, sizeof(data.m_FileSHA));
data.m_ulFileSize = file_size_(pszFileName);
//TODO data.m_unFlags; 0 is file //TODO: check if 64 is folder
} else {
data.m_eResult = k_EResultFileNotFound;
}
std::lock_guard<std::recursive_mutex> lock(global_mutex);
return callback_results->addCallResult(data.k_iCallback, &data, sizeof(data));
}
// Get command line if game was launched via Steam URL, e.g. steam://run/<appid>//<command line>/.