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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*
This file is a part of "Didrole's Update Tool"
©2k12, Didrole
License : Public domain
*/
#include <sys/stat.h>
#include "Open Steamworks/Steamworks.h"
extern IClientApps* g_pClientApps;
const char* GetAppName(AppId_t uAppId)
{
static char szName[25][256];
static unsigned int i = 0;
i = (i + 1) % (sizeof(szName) / sizeof(*szName));
int iSize = g_pClientApps->GetAppData(uAppId, "common/name", szName[i], sizeof(szName[i]));
if(iSize <= 0)
strcpy(szName[i], "Unknown App");
return szName[i];
}
void FormatSize(char* szOutput, unsigned int uOutputSize, unsigned long long ullBytes)
{
static const char *suffixes[] = {"iB", "KiB", "MiB", "GiB", "TiB", "PiB"};
int i;
long double flSize = ullBytes;
for(i = 0; flSize >= 1024 && i < sizeof(suffixes) / sizeof(*suffixes) - 1 ; flSize /= 1024, i++);
szOutput[uOutputSize - 1] = '\0';
snprintf(szOutput, uOutputSize - 1, "%.2Lf %s", flSize, suffixes[i]);
}
bool IsDir(const char* cszPath)
{
#ifdef _WIN32
DWORD dwAttrib = GetFileAttributesA(cszPath);
return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
#else
struct stat dirStat;
if(stat(cszPath, &dirStat) != 0 || !S_ISDIR(dirStat.st_mode))
return false;
return true;
#endif
}
void mSleep(unsigned int uMS)
{
#ifdef _WIN32
Sleep(uMS);
#else
usleep(uMS * 1000);
#endif
}
|