summaryrefslogtreecommitdiffstats
path: root/utils.cpp
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2013-03-09 15:14:01 +0100
committermanuel <manuel@mausz.at>2013-03-09 15:14:01 +0100
commit41f7119d8631a142fa5a97285a8443f9d7eb7e14 (patch)
tree75e35bffcfc8e82c989331335e11bac0c86da131 /utils.cpp
downloadsteamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.tar.gz
steamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.tar.bz2
steamcmd-41f7119d8631a142fa5a97285a8443f9d7eb7e14.zip
initial import of UpdateTool 0.4
Diffstat (limited to 'utils.cpp')
-rw-r--r--utils.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/utils.cpp b/utils.cpp
new file mode 100644
index 0000000..1a82531
--- /dev/null
+++ b/utils.cpp
@@ -0,0 +1,60 @@
1/*
2 This file is a part of "Didrole's Update Tool"
3 ©2k12, Didrole
4
5 License : Public domain
6*/
7
8#include <sys/stat.h>
9#include "../../Open Steamworks/Steamworks.h"
10
11extern IClientApps* g_pClientApps;
12
13const char* GetAppName(AppId_t uAppId)
14{
15 static char szName[25][256];
16 static unsigned int i = 0;
17 i = (i + 1) % (sizeof(szName) / sizeof(*szName));
18
19 int iSize = g_pClientApps->GetAppData(uAppId, "common/name", szName[i], sizeof(szName[i]));
20 if(iSize <= 0)
21 strcpy(szName[i], "Unknown App");
22
23 return szName[i];
24}
25
26void FormatSize(char* szOutput, unsigned int uOutputSize, unsigned long long ullBytes)
27{
28 static const char *suffixes[] = {"iB", "KiB", "MiB", "GiB", "TiB", "PiB"};
29
30 int i;
31 long double flSize = ullBytes;
32 for(i = 0; flSize >= 1024 && i < sizeof(suffixes) / sizeof(*suffixes) - 1 ; flSize /= 1024, i++);
33
34 szOutput[uOutputSize - 1] = '\0';
35 snprintf(szOutput, uOutputSize - 1, "%.2Lf %s", flSize, suffixes[i]);
36}
37
38bool IsDir(const char* cszPath)
39{
40#ifdef _WIN32
41 DWORD dwAttrib = GetFileAttributesA(cszPath);
42
43 return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
44#else
45 struct stat dirStat;
46 if(stat(cszPath, &dirStat) != 0 || !S_ISDIR(dirStat.st_mode))
47 return false;
48
49 return true;
50#endif
51}
52
53void mSleep(unsigned int uMS)
54{
55#ifdef _WIN32
56 Sleep(uMS);
57#else
58 usleep(uMS * 1000);
59#endif
60}