fix woz file handling

This commit is contained in:
Christopher A. Mosher 2022-12-08 20:33:52 -05:00
parent d3c3cfe0c8
commit 28048d7087
3 changed files with 20 additions and 18 deletions

View File

@ -229,12 +229,12 @@ elseif(WIN32)
PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-" PRE_EXCLUDE_REGEXES "api-ms-" "ext-ms-"
POST_EXCLUDE_REGEXES ".*system32/.*\\.dll" POST_EXCLUDE_REGEXES ".*system32/.*\\.dll"
BUNDLE DESTINATION . BUNDLE DESTINATION .
RESOURCE DESTINATION share/Resources) RESOURCE DESTINATION share/Resources PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
else() else()
install(TARGETS ${APP_NAME} install(TARGETS ${APP_NAME}
RUNTIME_DEPENDENCIES RUNTIME_DEPENDENCIES
DIRECTORIES ${CMAKE_SYSTEM_LIBRARY_PATH} DIRECTORIES ${CMAKE_SYSTEM_LIBRARY_PATH}
RESOURCE DESTINATION share/Resources) RESOURCE DESTINATION share/Resources PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
endif() endif()

View File

@ -19,6 +19,7 @@
#include "wozfile.h" #include "wozfile.h"
#include "E2wxApp.h" #include "E2wxApp.h"
#include "e2filesystem.h"
#include <istream> #include <istream>
#include <ostream> #include <ostream>
@ -111,19 +112,15 @@ void WozFile::dumpTracks() {
} }
} }
bool WozFile::load(const std::string& filePath) { bool WozFile::load(const std::filesystem::path& orig_file) {
printf("Reading WOZ 2.0 file: %s\n", filePath.c_str()); printf("Reading WOZ 2.0 file: %s\n", orig_file.c_str());
std::ifstream *in = new std::ifstream(filePath.c_str(), std::ios::binary|std::ios::in); std::filesystem::path filePath = valid_input_file(orig_file, wxGetApp().GetResDir());
std::ifstream *in = new std::ifstream(filePath, std::ios::binary|std::ios::in);
if (!in->is_open()) { if (!in->is_open()) {
std::filesystem::path f = wxGetApp().GetResDir(); printf("Error opening file: %d\n", errno);
f /= filePath.c_str(); delete in;
in = new std::ifstream(f.c_str(), std::ios::binary|std::ios::in); return false;
if (!in->is_open()) {
printf("Error opening file: %d\n", errno);
delete in;
return false;
}
} }
if (isLoaded()) { if (isLoaded()) {
unload(); unload();
@ -185,7 +182,7 @@ bool WozFile::load(const std::string& filePath) {
this->timing = buf[39]; this->timing = buf[39];
printf("Timing: %d/8 microseconds per bit\n", this->timing); printf("Timing: %d/8 microseconds per bit\n", this->timing);
std::uint16_t compat = *((std::uint16_t*)buf+40); std::uint16_t compat = *((std::uint16_t*)buf+40);
printf("Campatible hardware: "); printf("Compatible hardware: ");
if (!compat) { if (!compat) {
printf("unknown\n"); printf("unknown\n");
} else { } else {
@ -321,8 +318,13 @@ void WozFile::checkForWriteProtection() {
return; return;
} }
// TODO: fix; if the file doesn't exist this creates an empty file if (!std::filesystem::exists(this->filePath)) {
std::ofstream outf(filePath.c_str(),std::ios::binary|std::ios::app); this->writable = false;
}
std::filesystem::path canon = std::filesystem::canonical(this->filePath);
std::ofstream outf(canon, std::ios::binary|std::ios::app);
this->writable = outf.is_open(); this->writable = outf.is_open();
outf.close(); outf.close();
} }
@ -336,7 +338,7 @@ void WozFile::save() {
reduceTracks(); reduceTracks();
std::ofstream out(filePath.c_str(), std::ios::binary); std::ofstream out(this->filePath, std::ios::binary);
std::uint32_t woz2(0x325A4F57u); std::uint32_t woz2(0x325A4F57u);
out.write((char*)&woz2, sizeof(woz2)); out.write((char*)&woz2, sizeof(woz2));

View File

@ -110,7 +110,7 @@ public:
WozFile(); WozFile();
~WozFile(); ~WozFile();
bool load(const std::string& filePath); bool load(const std::filesystem::path& filePath);
bool isLoaded() const { bool isLoaded() const {
return this->loaded; return this->loaded;