Skip to content

Commit e1185d7

Browse files
steampp: migrate to std::filesystem::path over storing everything in strings
1 parent 4461165 commit e1185d7

File tree

4 files changed

+83
-86
lines changed

4 files changed

+83
-86
lines changed

include/steampp/steampp.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
#pragma once
66

77
#include <cstddef>
8+
#include <filesystem>
9+
#include <span>
810
#include <string>
911
#include <string_view>
1012
#include <unordered_map>
1113
#include <vector>
1214

1315
#include <kvpp/KV1Binary.h>
14-
#include <sourcepp/Math.h>
1516

1617
namespace steampp {
1718

@@ -21,29 +22,29 @@ class Steam {
2122
public:
2223
Steam();
2324

24-
[[nodiscard]] std::string_view getInstallDir() const;
25+
[[nodiscard]] const std::filesystem::path& getInstallDir() const;
2526

26-
[[nodiscard]] const std::vector<std::string>& getLibraryDirs() const;
27+
[[nodiscard]] std::span<const std::filesystem::path> getLibraryDirs() const;
2728

28-
[[nodiscard]] std::string getSourceModDir() const;
29+
[[nodiscard]] std::filesystem::path getSourceModDir() const;
2930

3031
[[nodiscard]] std::vector<AppID> getInstalledApps() const;
3132

3233
[[nodiscard]] bool isAppInstalled(AppID appID) const;
3334

3435
[[nodiscard]] std::string_view getAppName(AppID appID) const;
3536

36-
[[nodiscard]] std::string getAppInstallDir(AppID appID) const;
37+
[[nodiscard]] std::filesystem::path getAppInstallDir(AppID appID) const;
3738

38-
[[nodiscard]] std::string getAppIconPath(AppID appID) const;
39+
[[nodiscard]] std::filesystem::path getAppIconPath(AppID appID) const;
3940

40-
[[nodiscard]] std::string getAppLogoPath(AppID appID) const;
41+
[[nodiscard]] std::filesystem::path getAppLogoPath(AppID appID) const;
4142

42-
[[nodiscard]] std::string getAppHeroPath(AppID appID) const;
43+
[[nodiscard]] std::filesystem::path getAppHeroPath(AppID appID) const;
4344

44-
[[nodiscard]] std::string getAppBoxArtPath(AppID appID) const;
45+
[[nodiscard]] std::filesystem::path getAppBoxArtPath(AppID appID) const;
4546

46-
[[nodiscard]] std::string getAppStoreArtPath(AppID appID) const;
47+
[[nodiscard]] std::filesystem::path getAppStoreArtPath(AppID appID) const;
4748

4849
[[nodiscard]] bool isAppUsingGoldSrcEngine(AppID appID) const;
4950

@@ -56,13 +57,13 @@ class Steam {
5657
private:
5758
struct GameInfo {
5859
std::string name;
59-
std::string installDir;
60+
std::filesystem::path installDir;
6061
std::size_t libraryInstallDirsIndex;
6162
};
6263

6364
std::unordered_map<AppID, GameInfo> gameDetails;
64-
std::string steamInstallDir;
65-
std::vector<std::string> libraryDirs;
65+
std::filesystem::path steamInstallDir;
66+
std::vector<std::filesystem::path> libraryDirs;
6667
kvpp::KV1Binary assetCache;
6768
};
6869

lang/c/include/steamppc/steampp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SOURCEPP_TYPEDF(steampp, appid, uint32_t);
88
SOURCEPP_HANDLE(steampp, steam);
99
SOURCEPP_STATIC(steampp, steam, steampp_steam_handle_t, new); // REQUIRES MANUAL FREE: steampp_steam_free
1010
SOURCEPP_STATIC(steampp, steam, void, free, steampp_steam_handle_t* handle);
11-
SOURCEPP_METHOD(steampp, steam, const char*, get_install_dir);
11+
SOURCEPP_METHOD(steampp, steam, sourcepp_string_t, get_install_dir);
1212
SOURCEPP_METHOD(steampp, steam, sourcepp_string_array_t, get_library_dirs); // REQUIRES MANUAL FREE: sourcepp_string_array_free
1313
SOURCEPP_METHOD(steampp, steam, sourcepp_string_t, get_sourcemod_dir); // REQUIRES MANUAL FREE: sourcepp_string_free
1414
SOURCEPP_METHOD(steampp, steam, sourcepp_buffer_uint32_t, get_installed_apps); // REQUIRES MANUAL FREE: sourcepp_buffer_free

lang/c/src/steamppc/steampp.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,26 @@ SOURCEPP_STATIC(steampp, steam, void, free, steampp_steam_handle_t* handle) {
2424
*handle = nullptr;
2525
}
2626

27-
SOURCEPP_METHOD(steampp, steam, const char*, get_install_dir) {
28-
SOURCEPP_EARLY_RETURN_VAL(handle, "");
27+
SOURCEPP_METHOD(steampp, steam, sourcepp_string_t, get_install_dir) {
28+
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
2929

30-
return Convert::steam(handle)->getInstallDir().data();
30+
return Convert::toString(Convert::steam(handle)->getInstallDir().string());
3131
}
3232

3333
SOURCEPP_METHOD(steampp, steam, sourcepp_string_array_t, get_library_dirs) {
3434
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_ARRAY_INVALID);
3535

36-
return Convert::toStringArray(Convert::steam(handle)->getLibraryDirs());
36+
std::vector<std::string> libraryDirs;
37+
for (const auto& dir : Convert::steam(handle)->getLibraryDirs()) {
38+
libraryDirs.push_back(dir.string());
39+
}
40+
return Convert::toStringArray(libraryDirs);
3741
}
3842

3943
SOURCEPP_METHOD(steampp, steam, sourcepp_string_t, get_sourcemod_dir) {
4044
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
4145

42-
return Convert::toString(Convert::steam(handle)->getSourceModDir());
46+
return Convert::toString(Convert::steam(handle)->getSourceModDir().string());
4347
}
4448

4549
SOURCEPP_METHOD(steampp, steam, sourcepp_buffer_uint32_t, get_installed_apps) {
@@ -69,37 +73,37 @@ SOURCEPP_METHOE(steampp, steam, const char*, get_app_name, steampp_appid_t appID
6973
SOURCEPP_METHOE(steampp, steam, sourcepp_string_t, get_app_install_dir, steampp_appid_t appID) {
7074
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
7175

72-
return Convert::toString(Convert::steam(handle)->getAppInstallDir(appID));
76+
return Convert::toString(Convert::steam(handle)->getAppInstallDir(appID).string());
7377
}
7478

7579
SOURCEPP_METHOE(steampp, steam, sourcepp_string_t, get_app_icon_path, steampp_appid_t appID) {
7680
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
7781

78-
return Convert::toString(Convert::steam(handle)->getAppIconPath(appID));
82+
return Convert::toString(Convert::steam(handle)->getAppIconPath(appID).string());
7983
}
8084

8185
SOURCEPP_METHOE(steampp, steam, sourcepp_string_t, get_app_logo_path, steampp_appid_t appID) {
8286
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
8387

84-
return Convert::toString(Convert::steam(handle)->getAppLogoPath(appID));
88+
return Convert::toString(Convert::steam(handle)->getAppLogoPath(appID).string());
8589
}
8690

8791
SOURCEPP_METHOE(steampp, steam, sourcepp_string_t, get_app_hero_path, steampp_appid_t appID) {
8892
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
8993

90-
return Convert::toString(Convert::steam(handle)->getAppHeroPath(appID));
94+
return Convert::toString(Convert::steam(handle)->getAppHeroPath(appID).string());
9195
}
9296

9397
SOURCEPP_METHOE(steampp, steam, sourcepp_string_t, get_app_box_art_path, steampp_appid_t appID) {
9498
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
9599

96-
return Convert::toString(Convert::steam(handle)->getAppBoxArtPath(appID));
100+
return Convert::toString(Convert::steam(handle)->getAppBoxArtPath(appID).string());
97101
}
98102

99103
SOURCEPP_METHOE(steampp, steam, sourcepp_string_t, get_app_store_art_path, steampp_appid_t appID) {
100104
SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID);
101105

102-
return Convert::toString(Convert::steam(handle)->getAppStoreArtPath(appID));
106+
return Convert::toString(Convert::steam(handle)->getAppStoreArtPath(appID).string());
103107
}
104108

105109
SOURCEPP_METHOE(steampp, steam, int, is_app_using_goldsrc_engine, steampp_appid_t appID) {

0 commit comments

Comments
 (0)