Skip to content

Commit feff77c

Browse files
committed
Autogenerate cache files if they don't exist
No longer required to have the activemods.cache and modspriority.cache files prepared in directory for ptr2plus mod loading to work. It'll make them if they don't exist.
1 parent 26b2129 commit feff77c

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

pcsx2/mods/ActiveMods.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ static std::string ActiveMods::GetFilename()
88
{
99
return Path::Combine(EmuFolders::Cache, "activemods.cache");
1010
}
11+
12+
static bool ActiveMods::CacheFileValidation()
13+
{
14+
const std::string activemods_filename(GetFilename());
15+
if (FileSystem::FileExists(activemods_filename.c_str()))
16+
return true;
17+
else
18+
{
19+
u16 data = 0;
20+
return FileSystem::WriteBinaryFile(activemods_filename.c_str(), &data, 2);
21+
}
22+
}
1123
/* This would be quicker
1224
bool ActiveMods::ContainsMod(const std::string mod)
1325
{
@@ -43,6 +55,9 @@ bool ActiveMods::ContainsMod(const std::string mod)
4355
}
4456
bool ActiveMods::GetPaths(const std::string mod, std::vector<std::string>& paths)
4557
{
58+
if (!CacheFileValidation())
59+
return false;
60+
4661
const std::string activemods_filename(GetFilename());
4762

4863
const auto fp = FileSystem::OpenManagedCFile(activemods_filename.c_str(), "rb");
@@ -65,6 +80,9 @@ bool ActiveMods::GetPaths(const std::string mod, std::vector<std::string>& paths
6580

6681
bool ActiveMods::GetMod(const std::string path, std::string& mod)
6782
{
83+
if (!CacheFileValidation())
84+
return false;
85+
6886
const std::string activemods_filename(GetFilename());
6987

7088
const auto fp = FileSystem::OpenManagedCFile(activemods_filename.c_str(), "rb");
@@ -88,6 +106,7 @@ bool ActiveMods::GetMod(const std::string path, std::string& mod)
88106

89107
std::vector<std::pair<std::string, std::string>> ActiveMods::GetAll()
90108
{
109+
CacheFileValidation(); //todo: error handling
91110
const std::string activemods_filename(GetFilename());
92111
auto fp = FileSystem::OpenManagedCFile(activemods_filename.c_str(), "rb+");
93112
auto stream = fp.get();
@@ -215,6 +234,8 @@ bool ActiveMods::ReadOne(FILE* stream, std::pair<std::string, std::string>& entr
215234
//path, modname
216235
bool ActiveMods::Save(std::vector<std::pair<std::string, std::string>> activeModCache)
217236
{
237+
if (!CacheFileValidation())
238+
return false;
218239
const std::string activemods_filename(GetFilename());
219240

220241
FileSystem::DeleteFilePath(activemods_filename.c_str());

pcsx2/mods/ActiveMods.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace ActiveMods
44
{
55
static std::string GetFilename();
66

7+
static bool CacheFileValidation();
8+
79
bool ReadOne(FILE* stream, std::pair<std::string, std::string>& entry);
810

911
bool ContainsMod(const std::string mod);

pcsx2/mods/PriorityList.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@ static std::string PriorityList::GetFilename()
1010
return Path::Combine(EmuFolders::Cache, "modpriority.cache");
1111
}
1212

13+
static bool PriorityList::CacheFileValidation()
14+
{
15+
const std::string modspriority_filename(GetFilename());
16+
if (FileSystem::FileExists(modspriority_filename.c_str()))
17+
return true;
18+
else
19+
{
20+
u16 data = 0;
21+
return FileSystem::WriteBinaryFile(modspriority_filename.c_str(), &data, 2);
22+
}
23+
}
24+
1325
//returns list of modnames in order from highest to lowest priority (0 first
1426
std::vector<std::string> PriorityList::Get()
1527
{
28+
CacheFileValidation(); //todo: error handling
29+
1630
const std::string modspriority_filename(GetFilename());
1731

1832
auto fp = FileSystem::OpenManagedCFile(modspriority_filename.c_str(), "rb+");
@@ -45,6 +59,9 @@ std::vector<std::string> PriorityList::Get()
4559
}
4660
bool PriorityList::GetPriority(std::string modname, int& priority)
4761
{
62+
if (!CacheFileValidation())
63+
return false;
64+
4865
const std::string modspriority_filename(GetFilename());
4966

5067
auto fp = FileSystem::OpenManagedCFile(modspriority_filename.c_str(), "rb+");
@@ -77,6 +94,9 @@ bool PriorityList::GetPriority(std::string modname, int& priority)
7794
}
7895
bool PriorityList::GetModName(int priority, std::string& modname)
7996
{
97+
if (!CacheFileValidation())
98+
return false;
99+
80100
const std::string modspriority_filename(GetFilename());
81101

82102
auto fp = FileSystem::OpenManagedCFile(modspriority_filename.c_str(), "rb+");
@@ -109,6 +129,9 @@ bool PriorityList::GetModName(int priority, std::string& modname)
109129
}
110130
bool PriorityList::Save(std::vector<std::string> priority_list)
111131
{
132+
if (!CacheFileValidation())
133+
return false;
134+
112135
const std::string modspriority_filename(GetFilename());
113136
FileSystem::DeleteFilePath(modspriority_filename.c_str());
114137

pcsx2/mods/PriorityList.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace PriorityList
33
{
44
static std::string GetFilename();
5+
static bool CacheFileValidation();
56
std::vector<std::string> Get();
67
bool GetPriority(std::string modname, int& priority);
78
bool GetModName(int priority, std::string& modname);

0 commit comments

Comments
 (0)