DEV9: Use fs namespace instead of ghc

This commit is contained in:
TheLastRar 2022-02-06 16:00:23 +00:00 committed by lightningterror
parent 30bc9b04c5
commit dcc183179a
6 changed files with 34 additions and 41 deletions

View File

@ -20,7 +20,6 @@
#include <atomic> #include <atomic>
#include <mutex> #include <mutex>
#include <condition_variable> #include <condition_variable>
#include <ghc/filesystem.h>
#include <fstream> #include <fstream>
#include "DEV9/SimpleQueue.h" #include "DEV9/SimpleQueue.h"
@ -154,7 +153,7 @@ private:
public: public:
ATA(); ATA();
int Open(ghc::filesystem::path hddPath); int Open(fs::path hddPath);
void Close(); void Close();
void ATA_HardReset(); void ATA_HardReset();

View File

@ -26,7 +26,7 @@ ATA::ATA()
ResetEnd(true); ResetEnd(true);
} }
int ATA::Open(ghc::filesystem::path hddPath) int ATA::Open(fs::path hddPath)
{ {
readBufferLen = 256 * 512; readBufferLen = 256 * 512;
readBuffer = new u8[readBufferLen]; readBuffer = new u8[readBufferLen];
@ -34,7 +34,7 @@ int ATA::Open(ghc::filesystem::path hddPath)
CreateHDDinfo(config.HddSize); CreateHDDinfo(config.HddSize);
//Open File //Open File
if (!ghc::filesystem::exists(hddPath)) if (!fs::exists(hddPath))
{ {
HddCreate hddCreator; HddCreate hddCreator;
hddCreator.filePath = hddPath; hddCreator.filePath = hddPath;
@ -44,7 +44,7 @@ int ATA::Open(ghc::filesystem::path hddPath)
if (hddCreator.errored) if (hddCreator.errored)
return -1; return -1;
} }
hddImage = ghc::filesystem::fstream(hddPath, std::ios::in | std::ios::out | std::ios::binary); hddImage = fs::fstream(hddPath, std::ios::in | std::ios::out | std::ios::binary);
//Store HddImage size for later check //Store HddImage size for later check
hddImage.seekg(0, std::ios::end); hddImage.seekg(0, std::ios::end);

View File

@ -78,18 +78,18 @@ void HddCreate::Start()
completedCV.notify_all(); completedCV.notify_all();
} }
void HddCreate::WriteImage(ghc::filesystem::path hddPath, int reqSizeMiB) void HddCreate::WriteImage(fs::path hddPath, int reqSizeMiB)
{ {
constexpr int buffsize = 4 * 1024; constexpr int buffsize = 4 * 1024;
u8 buff[buffsize] = {0}; //4kb u8 buff[buffsize] = {0}; //4kb
if (ghc::filesystem::exists(hddPath)) if (fs::exists(hddPath))
{ {
SetError(); SetError();
return; return;
} }
std::fstream newImage = ghc::filesystem::fstream(hddPath, std::ios::out | std::ios::binary); std::fstream newImage = fs::fstream(hddPath, std::ios::out | std::ios::binary);
if (newImage.fail()) if (newImage.fail())
{ {
@ -105,7 +105,7 @@ void HddCreate::WriteImage(ghc::filesystem::path hddPath, int reqSizeMiB)
if (newImage.fail()) if (newImage.fail())
{ {
newImage.close(); newImage.close();
ghc::filesystem::remove(filePath); fs::remove(filePath);
SetError(); SetError();
return; return;
} }
@ -122,7 +122,7 @@ void HddCreate::WriteImage(ghc::filesystem::path hddPath, int reqSizeMiB)
if (newImage.fail()) if (newImage.fail())
{ {
newImage.close(); newImage.close();
ghc::filesystem::remove(filePath); fs::remove(filePath);
SetError(); SetError();
return; return;
} }
@ -137,7 +137,7 @@ void HddCreate::WriteImage(ghc::filesystem::path hddPath, int reqSizeMiB)
if (canceled.load()) if (canceled.load())
{ {
newImage.close(); newImage.close();
ghc::filesystem::remove(filePath); fs::remove(filePath);
SetError(); SetError();
return; return;
} }

View File

@ -24,12 +24,11 @@
#include <atomic> #include <atomic>
#include <condition_variable> #include <condition_variable>
#include <chrono> #include <chrono>
#include "ghc/filesystem.h"
class HddCreate class HddCreate
{ {
public: public:
ghc::filesystem::path filePath; fs::path filePath;
int neededSize; int neededSize;
std::atomic_bool errored{false}; std::atomic_bool errored{false};
@ -56,5 +55,5 @@ public:
private: private:
void SetFileProgress(int currentSize); void SetFileProgress(int currentSize);
void SetError(); void SetError();
void WriteImage(ghc::filesystem::path hddPath, int reqSizeMB); void WriteImage(fs::path hddPath, int reqSizeMB);
}; };

View File

@ -18,7 +18,6 @@
#include <stdio.h> #include <stdio.h>
#include <vector> #include <vector>
#include <ghc/filesystem.h>
#include <wx/wx.h> #include <wx/wx.h>
#include <wx/collpane.h> #include <wx/collpane.h>
@ -383,16 +382,16 @@ void DEV9configure()
ConfigDEV9 oldConfig = config; ConfigDEV9 oldConfig = config;
dialog.Save(config); dialog.Save(config);
ghc::filesystem::path hddPath(config.Hdd); fs::path hddPath(config.Hdd);
if (hddPath.is_relative()) if (hddPath.is_relative())
{ {
//GHC uses UTF8 on all platforms //GHC uses UTF8 on all platforms
ghc::filesystem::path path(EmuFolders::Settings.ToString().wx_str()); fs::path path(EmuFolders::Settings.ToString().wx_str());
hddPath = path / hddPath; hddPath = path / hddPath;
} }
if (config.hddEnable && !ghc::filesystem::exists(hddPath)) if (config.hddEnable && !fs::exists(hddPath))
{ {
HddCreate hddCreator; HddCreate hddCreator;
hddCreator.filePath = hddPath; hddCreator.filePath = hddPath;

View File

@ -25,8 +25,6 @@
#include <err.h> #include <err.h>
#endif #endif
#include "ghc/filesystem.h"
#include <fcntl.h> #include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -96,6 +94,23 @@ std::string s_strLogPath = "logs";
bool isRunning = false; bool isRunning = false;
fs::path GetHDDPath()
{
//GHC uses UTF8 on all platforms
fs::path hddPath(config.Hdd);
if (hddPath.empty())
config.hddEnable = false;
if (hddPath.is_relative())
{
fs::path path(EmuFolders::Settings.ToString().wx_str());
hddPath = path / hddPath;
}
return hddPath;
}
s32 DEV9init() s32 DEV9init()
{ {
DevCon.WriteLn("DEV9: DEV9init"); DevCon.WriteLn("DEV9: DEV9init");
@ -196,16 +211,7 @@ s32 DEV9open()
DevCon.WriteLn("DEV9: open r+: %s", config.Hdd); DevCon.WriteLn("DEV9: open r+: %s", config.Hdd);
#endif #endif
ghc::filesystem::path hddPath(config.Hdd); fs::path hddPath = GetHDDPath();
if (hddPath.empty())
config.hddEnable = false;
if (hddPath.is_relative())
{
ghc::filesystem::path path(EmuFolders::Settings.ToString().wx_str());
hddPath = path / hddPath;
}
if (config.hddEnable) if (config.hddEnable)
{ {
@ -1084,17 +1090,7 @@ void ApplyConfigIfRunning(ConfigDEV9 oldConfig)
//Hdd //Hdd
//Hdd Validate Path //Hdd Validate Path
ghc::filesystem::path hddPath(config.Hdd); fs::path hddPath = GetHDDPath();
if (hddPath.empty())
config.hddEnable = false;
if (hddPath.is_relative())
{
//GHC uses UTF8 on all platforms
ghc::filesystem::path path(EmuFolders::Settings.ToString().wx_str());
hddPath = path / hddPath;
}
//Hdd Compare with old config //Hdd Compare with old config
if (config.hddEnable) if (config.hddEnable)