- Статус
- Оффлайн
- Регистрация
- 3 Апр 2019
- Сообщения
- 429
- Реакции
- 117
как пофиксить эти ошибки?
вот код:
вот код:
C++:
#include "Settings.h"
#include <fstream>
bool Settings::Save(std::string file_name)
{
std::string file_path = "C:\\ZALUPA\\" + file_name + ".cfg";
std::fstream file(file_path, std::ios::out | std::ios::in | std::ios::trunc);
file.close();
file.open(file_path, std::ios::out | std::ios::in);
if (!file.is_open())
{
file.close();
return false;
}
const size_t settings_size = sizeof(g_Settings);
for (int i = 0; i < settings_size; i++)
{
byte current_byte = *reinterpret_cast<byte*>(uintptr_t(this) + i);
for (int x = 0; x < 8; x++)
{
file << (int)((current_byte >> x) & 1);
}
}
file.close();
return true;
}
bool Settings::Load(std::string file_name)
{
CreateDirectoryA("C:\\ZALUPA", NULL);
std::string file_path = "C:\\ZALUPA\\" + file_name + ".cfg";
std::fstream file;
file.open(file_path, std::ios::out | std::ios::in);
if (!file.is_open())
{
file.close();
return false;
}
std::string line;
while (file)
{
std::getline(file, line);
const size_t settings_size = sizeof(g_Settings);
if (line.size() > settings_size * 8)
{
file.close();
return false;
}
for (int i = 0; i < settings_size; i++)
{
byte current_byte = *reinterpret_cast<byte*>(uintptr_t(this) + i);
for (int x = 0; x < 8; x++)
{
if (line[(i * 8) + x] == '1')
current_byte |= 1 << x;
else
current_byte &= ~(1 << x);
}
*reinterpret_cast<byte*>(uintptr_t(this) + i) = current_byte;
}
}
file.close();
return true;
}
bool Settings::Remove(std::string file_name)
{
CreateDirectoryA("C:\\ZALUPA", NULL);
std::string file_path = "C:\\ZALUPA\\" + file_name + ".cfg";
remove(file_path.c_str());
return true;
}
void Settings::CreateConfig(std::string name)
{
CreateDirectoryA("C:\\ZALUPA\\", NULL); CreateDirectoryA("C:\\ZALUPA\\", NULL);
std::ofstream ofs("C:\\ZALUPA\\" + name + ".cfg");
}
std::vector<std::string> Settings::GetConfigs()
{
std::vector<std::string> configs;
WIN32_FIND_DATA ffd;
auto directory = "C:\\ZALUPA\\*";
auto hFind = FindFirstFileA(directory, &ffd);
while (FindNextFileA(hFind, &ffd))
{
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
std::string file_name = ffd.cFileName;
if (file_name.size() < 4) // .cfg
continue;
std::string end = file_name;
end.erase(end.begin(), end.end() - 4); // erase everything but the last 4 letters
if (end != ".cfg")
continue;
file_name.erase(file_name.end() - 4, file_name.end()); // erase the .cfg part
configs.push_back(file_name);
}
}
return configs;
}
Settings g_Settings;