-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 02. Timer & File - Virtual File / String
- system/FileSystem - system/VFS - utils/String
- Loading branch information
1 parent
8a14cc4
commit 78e41ce
Showing
11 changed files
with
456 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,51 @@ | ||
#include <iostream> | ||
|
||
#include "app/Application.h" | ||
#include "system/VFS.h" | ||
|
||
int main() | ||
{ | ||
std::cout << "Hello, Sunny Project!" << std::endl; | ||
//std::cout << "Hello, Sunny Project!" << std::endl; | ||
|
||
sunny::Application game("Test", {800, 600, false, false}); | ||
//sunny::Application game("Test", {800, 600, false, false}); | ||
|
||
game.Start(); | ||
//game.Start(); | ||
|
||
// std::string a = "dd// dd "; | ||
|
||
//std::cout << sunny::utils::FindToken(a, "dd");// << std::endl; | ||
|
||
//const char* ad = "SDfsaaaaaaaaaaaaaaaaaad"; | ||
|
||
//std::string b = std::string(ad, 5); | ||
|
||
//std::cout << b;// << std::endl; | ||
sunny::VFS::Init(); | ||
|
||
const std::string path = "sunny.h"; | ||
|
||
std::string a = sunny::VFS::Get()->ReadTextFile(path); | ||
unsigned char* a2 = sunny::VFS::Get()->ReadFile(path); | ||
std::cout << a << std::endl; | ||
std::cout << a2 << std::endl; | ||
|
||
if (! sunny::VFS::Get()->WriteFile("aa.h", a2) ) | ||
{ | ||
std::cout << "쓰기 실패1" << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "쓰기 성공1" << std::endl; | ||
} | ||
|
||
if (!sunny::VFS::Get()->WriteTextFile("aa2.h", a)) | ||
{ | ||
std::cout << "쓰기 실패2" << std::endl; | ||
} | ||
else | ||
{ | ||
std::cout << "쓰기 성공2" << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "VFS.h" | ||
|
||
namespace sunny | ||
{ | ||
VFS* VFS::s_instance = nullptr; | ||
|
||
void VFS::Init() | ||
{ | ||
s_instance = new VFS(); | ||
} | ||
|
||
void VFS::Shutdown() | ||
{ | ||
delete s_instance; | ||
} | ||
|
||
void VFS::Mount(const std::string& virtualPath, const std::string& physicalPath) | ||
{ | ||
if (!s_instance) | ||
{ | ||
// Debug System | ||
} | ||
|
||
m_mountPoints[virtualPath].push_back(physicalPath); | ||
} | ||
|
||
void VFS::UnMount(const std::string& path) | ||
{ | ||
if (!s_instance) | ||
{ | ||
// Debug System | ||
} | ||
|
||
m_mountPoints[path].clear(); | ||
} | ||
|
||
bool VFS::ResolvePhysicalPath(const std::string& path, std::string& outPhysicalPath) | ||
{ | ||
if (path[0] != '/') | ||
{ | ||
outPhysicalPath = path; | ||
return system::FileSystem::FileExists(path); | ||
} | ||
|
||
std::vector<std::string> dirs = utils::SplitString(path, '/'); | ||
|
||
const std::string& virtualDir = dirs.front(); | ||
|
||
if (m_mountPoints.find(virtualDir) == m_mountPoints.end() || m_mountPoints[virtualDir].empty()) | ||
return false; | ||
|
||
std::string remainder = path.substr(virtualDir.size() + 1, path.size() - virtualDir.size()); | ||
|
||
for (const std::string& physicalPath : m_mountPoints[virtualDir]) | ||
{ | ||
std::string path = physicalPath + remainder; | ||
if (system::FileSystem::FileExists(path)) | ||
{ | ||
outPhysicalPath = path; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
unsigned char* VFS::ReadFile(const std::string& path) | ||
{ | ||
if (!s_instance) | ||
{ | ||
// Debug System | ||
} | ||
std::string physicalPath; | ||
|
||
return ResolvePhysicalPath(path, physicalPath) ? system::FileSystem::ReadFile(physicalPath) : nullptr; | ||
} | ||
|
||
std::string VFS::ReadTextFile(const std::string& path) | ||
{ | ||
if (!s_instance) | ||
{ | ||
// Debug System | ||
} | ||
|
||
std::string physicalPath; | ||
|
||
return ResolvePhysicalPath(path, physicalPath) ? system::FileSystem::ReadTextFile(physicalPath) : nullptr; | ||
} | ||
|
||
bool VFS::WriteFile(const std::string& path, unsigned char* buffer) | ||
{ | ||
if (!s_instance) | ||
{ | ||
// Debug System | ||
} | ||
|
||
std::string physicalPath; | ||
|
||
return ResolvePhysicalPath(path, physicalPath) ? system::FileSystem::WriteFile(physicalPath, buffer) : nullptr; | ||
} | ||
|
||
bool VFS::WriteTextFile(const std::string& path, const std::string& text) | ||
{ | ||
if (!s_instance) | ||
{ | ||
// Debug System | ||
} | ||
|
||
std::string physicalPath; | ||
|
||
return ResolvePhysicalPath(path, physicalPath) ? system::FileSystem::WriteTextFile(physicalPath, text) : nullptr; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include "../sunny.h" | ||
#include "../utils/String.h" | ||
#include "FileSystem.h" | ||
|
||
namespace sunny | ||
{ | ||
class VFS | ||
{ | ||
private: | ||
static VFS* s_instance; | ||
|
||
private: | ||
std::unordered_map<std::string, std::vector<std::string>> m_mountPoints; | ||
|
||
public: | ||
void Mount(const std::string& virtualPath, const std::string& physicalPath); | ||
void UnMount(const std::string& path); | ||
|
||
bool ResolvePhysicalPath(const std::string& path, std::string& outPhysicalPath); | ||
|
||
unsigned char* ReadFile(const std::string& path); | ||
std::string ReadTextFile(const std::string& path); | ||
|
||
bool WriteFile(const std::string& path, unsigned char* buffer); | ||
bool WriteTextFile(const std::string& path, const std::string& text); | ||
|
||
public: | ||
static void Init(); | ||
static void Shutdown(); | ||
|
||
inline static VFS* Get() { return s_instance; } | ||
}; | ||
} |
Oops, something went wrong.