mirror of
https://github.com/johndoe6345789/WizardMerge.git
synced 2026-04-24 21:54:57 +00:00
Create multi-frontend architecture with qt6, nextjs, and cli frontends
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
47
frontends/cli/src/file_utils.cpp
Normal file
47
frontends/cli/src/file_utils.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "file_utils.h"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
bool FileUtils::readLines(const std::string& filePath, std::vector<std::string>& lines) {
|
||||
std::ifstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lines.clear();
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileUtils::writeLines(const std::string& filePath, const std::vector<std::string>& lines) {
|
||||
std::ofstream file(filePath);
|
||||
if (!file.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& line : lines) {
|
||||
file << line << "\n";
|
||||
}
|
||||
|
||||
file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileUtils::fileExists(const std::string& filePath) {
|
||||
struct stat buffer;
|
||||
return (stat(filePath.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
long FileUtils::getFileSize(const std::string& filePath) {
|
||||
struct stat buffer;
|
||||
if (stat(filePath.c_str(), &buffer) != 0) {
|
||||
return -1;
|
||||
}
|
||||
return buffer.st_size;
|
||||
}
|
||||
Reference in New Issue
Block a user