forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteam.cpp
98 lines (79 loc) · 1.95 KB
/
steam.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Aseprite Steam Wrapper
// Copyright (c) 2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "steam/steam.h"
#include "base/dll.h"
#include "base/fs.h"
#include "base/log.h"
#include "base/string.h"
namespace steam {
typedef bool (*SteamAPI_Init_Func)();
typedef void (*SteamAPI_Shutdown_Func)();
#ifdef _WIN32
#ifdef _WIN64
#define STEAM_API_DLL_FILENAME "steam_api64.dll"
#else
#define STEAM_API_DLL_FILENAME "steam_api.dll"
#endif
#elif defined(__APPLE__)
#define STEAM_API_DLL_FILENAME "libsteam_api.dylib"
#else
#define STEAM_API_DLL_FILENAME "libsteam_api.so"
#endif
class SteamAPI::Impl {
public:
Impl() : m_initialized(false) {
m_steamLib = base::load_dll(
base::join_path(base::get_file_path(base::get_app_path()),
STEAM_API_DLL_FILENAME));
if (!m_steamLib) {
LOG("STEAM: Steam library not found...\n");
return;
}
auto SteamAPI_Init = base::get_dll_proc<SteamAPI_Init_Func>(m_steamLib, "SteamAPI_Init");
if (!SteamAPI_Init) {
LOG("STEAM: SteamAPI_Init not found...\n");
return;
}
if (!SteamAPI_Init()) {
LOG("STEAM: Steam is not initialized...\n");
return;
}
LOG("STEAM: Steam initialized...\n");
m_initialized = true;
}
~Impl() {
if (!m_steamLib)
return;
auto SteamAPI_Shutdown = base::get_dll_proc<SteamAPI_Shutdown_Func>(m_steamLib, "SteamAPI_Shutdown");
if (SteamAPI_Shutdown) {
LOG("STEAM: Steam shutdown...\n");
SteamAPI_Shutdown();
}
base::unload_dll(m_steamLib);
}
bool initialized() const {
return m_initialized;
}
private:
base::dll m_steamLib;
bool m_initialized;
};
SteamAPI::SteamAPI()
: m_impl(new Impl)
{
}
SteamAPI::~SteamAPI()
{
delete m_impl;
}
bool SteamAPI::initialized() const
{
return m_impl->initialized();
}
} // namespace steam