mirror of
https://github.com/zeldaret/mm.git
synced 2026-06-20 07:31:39 -04:00
b6904aa2cc
* remove ZAPD submodule * git subrepo clone https://github.com/zeldaret/ZAPD.git tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "ca229f19" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "ca229f19" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * git subrepo clone https://github.com/simonlindholm/decomp-permuter.git tools/decomp-permuter subrepo: subdir: "tools/decomp-permuter" merged: "1e4b85a7" upstream: origin: "https://github.com/simonlindholm/decomp-permuter.git" branch: "main" commit: "1e4b85a7" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * Remove asm-differ * git subrepo clone https://github.com/simonlindholm/asm-differ.git tools/asm-differ subrepo: subdir: "tools/asm-differ" merged: "eaf72269" upstream: origin: "https://github.com/simonlindholm/asm-differ.git" branch: "master" commit: "eaf72269" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * remove asm-processor * git subrepo clone https://github.com/simonlindholm/asm-processor.git tools/asm-processor subrepo: subdir: "tools/asm-processor" merged: "85288fcd" upstream: origin: "https://github.com/simonlindholm/asm-processor.git" branch: "master" commit: "85288fcd" git-subrepo: version: "0.4.3" origin: "???" commit: "???" * remove .gitmodules file * Update REAMDE * Update warnings
66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "StringHelper.h"
|
|
|
|
class File
|
|
{
|
|
public:
|
|
static bool Exists(const std::string& filePath)
|
|
{
|
|
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
|
|
return file.good();
|
|
}
|
|
|
|
static std::vector<uint8_t> ReadAllBytes(const std::string& filePath)
|
|
{
|
|
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
|
|
int32_t fileSize = (int32_t)file.tellg();
|
|
file.seekg(0);
|
|
char* data = new char[fileSize];
|
|
file.read(data, fileSize);
|
|
std::vector<uint8_t> result = std::vector<uint8_t>(data, data + fileSize);
|
|
delete[] data;
|
|
|
|
return result;
|
|
};
|
|
|
|
static std::string ReadAllText(const std::string& filePath)
|
|
{
|
|
std::ifstream file(filePath, std::ios::in | std::ios::binary | std::ios::ate);
|
|
int32_t fileSize = (int32_t)file.tellg();
|
|
file.seekg(0);
|
|
char* data = new char[fileSize + 1];
|
|
memset(data, 0, fileSize + 1);
|
|
file.read(data, fileSize);
|
|
std::string str = std::string((const char*)data);
|
|
delete[] data;
|
|
|
|
return str;
|
|
};
|
|
|
|
static std::vector<std::string> ReadAllLines(const std::string& filePath)
|
|
{
|
|
std::string text = ReadAllText(filePath);
|
|
std::vector<std::string> lines = StringHelper::Split(text, "\n");
|
|
|
|
return lines;
|
|
};
|
|
|
|
static void WriteAllBytes(const std::string& filePath, const std::vector<uint8_t>& data)
|
|
{
|
|
std::ofstream file(filePath, std::ios::binary);
|
|
file.write((char*)data.data(), data.size());
|
|
};
|
|
|
|
static void WriteAllText(const std::string& filePath, const std::string& text)
|
|
{
|
|
std::ofstream file(filePath, std::ios::out);
|
|
file.write(text.c_str(), text.size());
|
|
}
|
|
};
|