-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "Scripts.h" | ||
|
||
//############################################## Data ##############################################// | ||
|
||
Data::Data(const int FileSize, const std::string FileName, const std::string FilePath) | ||
{ | ||
//Set Size | ||
Size = FileSize; | ||
Content = new std::string[Size]; | ||
|
||
//Create File Paths | ||
Path = std::filesystem::current_path() / FilePath / FileName; | ||
|
||
//Create File IF Not Exist | ||
if(!std::filesystem::exists(Path)){ | ||
std::filesystem::create_directory(Path.parent_path()); | ||
std::fstream Create(Path, std::ios::out); | ||
Create.close(); | ||
} | ||
|
||
//Read File | ||
std::fstream FileData(Path, std::ios::in); | ||
std::string Line; | ||
for(int Count = 0; Count < Size; Count++){ | ||
std::getline(FileData, Line); | ||
Content[Count] = Line; | ||
} | ||
FileData.close(); | ||
|
||
} | ||
|
||
void Data::Save(){ | ||
//Create Temp String | ||
std::string Temp; | ||
for(int Count = 0; Count < Size; Count++){ | ||
Temp += Content[Count] + "\n"; | ||
} | ||
Temp += "\0"; | ||
|
||
//Save Data | ||
std::fstream FileData(Path, std::ios::out); | ||
FileData << Temp; | ||
FileData.close(); | ||
|
||
} | ||
|
||
void Data::Add(const int Slot, const std::string Element){ | ||
Content[Slot] = Element; | ||
} | ||
|
||
bool Data::Exist(){ | ||
std::fstream FileData(Path, std::ios::in); | ||
std::string Check; | ||
FileData >> Check; | ||
FileData.close(); | ||
if(Check == "") return false; | ||
return true; | ||
|
||
} | ||
|
||
Data::~Data(){ | ||
delete[] Content; | ||
} |
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,21 @@ | ||
#pragma once | ||
#include <filesystem> | ||
#include <fstream> | ||
|
||
//############################################## Data ##############################################// | ||
|
||
class Data | ||
{ | ||
public: | ||
std::string* Content; | ||
std::filesystem::path Path; | ||
int Size = 0; | ||
|
||
public: | ||
Data(const int FileSize, const std::string FileName, const std::string FilePath = "Data/"); | ||
void Save(); | ||
void Add(const int Slot, const std::string Element); | ||
bool Exist(); | ||
~Data(); | ||
|
||
}; |