mirror of https://github.com/OpenRCT2/OpenRCT2.git
Prevent delete or rename on RCT2 tracks
This commit is contained in:
parent
29f75a71fb
commit
42d8324997
|
@ -45,11 +45,17 @@ struct TrackRepositoryItem
|
|||
std::string Path;
|
||||
uint8 RideType = 0;
|
||||
std::string ObjectEntry;
|
||||
uint32 Flags;
|
||||
};
|
||||
|
||||
constexpr uint32 TRACK_REPOISTORY_MAGIC_NUMBER = 0x58444954;
|
||||
constexpr uint16 TRACK_REPOISTORY_VERSION = 1;
|
||||
|
||||
enum TRACK_REPO_ITEM_FLAGS
|
||||
{
|
||||
TRIF_READ_ONLY = (1 << 0),
|
||||
};
|
||||
|
||||
class TrackDesignRepository : public ITrackDesignRepository
|
||||
{
|
||||
private:
|
||||
|
@ -108,7 +114,7 @@ public:
|
|||
utf8 directory[MAX_PATH];
|
||||
|
||||
GetRCT2Directory(directory, sizeof(directory));
|
||||
Scan(directory);
|
||||
Scan(directory, TRIF_READ_ONLY);
|
||||
|
||||
GetUserDirectory(directory, sizeof(directory));
|
||||
Scan(directory);
|
||||
|
@ -120,14 +126,18 @@ public:
|
|||
bool Delete(const utf8 * path) override
|
||||
{
|
||||
bool result = false;
|
||||
if (platform_file_delete(path))
|
||||
{
|
||||
size_t index = GetTrackIndex(path);
|
||||
if (index != SIZE_MAX)
|
||||
{
|
||||
const TrackRepositoryItem * item = &_items[index];
|
||||
if (!(item->Flags & TRIF_READ_ONLY))
|
||||
{
|
||||
if (platform_file_delete(path))
|
||||
{
|
||||
_items.erase(_items.begin() + index);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -138,7 +148,8 @@ public:
|
|||
if (index != SIZE_MAX)
|
||||
{
|
||||
TrackRepositoryItem * item = &_items[index];
|
||||
|
||||
if (!item->Flags & TRIF_READ_ONLY)
|
||||
{
|
||||
utf8 newPath[MAX_PATH];
|
||||
Path::GetDirectory(newPath, sizeof(newPath), path);
|
||||
Path::Append(newPath, sizeof(newPath), newName);
|
||||
|
@ -157,6 +168,7 @@ public:
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -184,7 +196,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
void Scan(const utf8 * directory)
|
||||
void Scan(const utf8 * directory, uint32 flags = 0)
|
||||
{
|
||||
utf8 pattern[MAX_PATH];
|
||||
String::Set(pattern, sizeof(pattern), directory);
|
||||
|
@ -194,11 +206,11 @@ private:
|
|||
while (fileEnumerator.Next())
|
||||
{
|
||||
const utf8 * path = fileEnumerator.GetPath();
|
||||
AddTrack(path);
|
||||
AddTrack(path, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void AddTrack(const utf8 * path)
|
||||
void AddTrack(const utf8 * path, uint32 flags = 0)
|
||||
{
|
||||
rct_track_td6 * td6 = track_design_open(path);
|
||||
if (td6 != nullptr)
|
||||
|
@ -208,6 +220,7 @@ private:
|
|||
item.Path = std::string(path);
|
||||
item.RideType = td6->type;
|
||||
item.ObjectEntry = std::string(td6->vehicle_object.name, 8);
|
||||
item.Flags = flags;
|
||||
_items.push_back(item);
|
||||
track_design_dispose(td6);
|
||||
}
|
||||
|
@ -252,6 +265,7 @@ private:
|
|||
fs.WriteString(item.Path);
|
||||
fs.WriteValue(item.RideType);
|
||||
fs.WriteString(item.ObjectEntry);
|
||||
fs.WriteValue(item.Flags);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
Loading…
Reference in New Issue