<commit_before>#include "FileIO.h"
#include "widget_id.h"
#include "Symbol.h"
#include "Sprite.h"
#include "ChangeWindowViewSizeSJ.h"

#include <ee/FileHelper.h>
#include <ee/SymbolSearcher.h>
#include <ee/SymbolMgr.h>
#include <ee/SpriteFactory.h>
#include <ee/FetchAllVisitor.h>

#include <easycomplex.h>

#include <fstream>

namespace eui
{
namespace window
{

void FileIO::Store(const char* filepath, const Symbol* sym)
{
	Json::Value value;

	std::string dir = ee::FileHelper::GetFileDir(filepath) + "\\";

	value["type"] = get_widget_desc(ID_WINDOW);
	value["name"] = sym->name;

	sym->GetAnchorMgr().StoreToFile(value, dir);

	value["view"]["width"] = sym->GetWidth();
	value["view"]["height"] = sym->GetHeight();

	std::vector<ee::Sprite*> sprites;
	const_cast<Symbol*>(sym)->GetAnchorMgr().Traverse(ee::FetchAllVisitor<ee::Sprite>(sprites));
	StoreWrapper(filepath, sym->name, sprites);

	StoreRefs(value, sym, dir);

	Json::StyledStreamWriter writer;
	std::locale::global(std::locale(""));
	std::ofstream fout(filepath);
	std::locale::global(std::locale("C"));	
	writer.write(fout, value);
	fout.close();
}

void FileIO::Load(const char* filepath, Symbol* sym)
{
	Json::Value value;
	Json::Reader reader;
	std::locale::global(std::locale(""));
	std::ifstream fin(filepath);
	std::locale::global(std::locale("C"));
	reader.parse(fin, value);
	fin.close();

	std::string type = value["type"].asString();
	if (!type.empty() && !is_widget(type, ID_WINDOW)) {
		return;
	}

	sym->name = value["name"].asString();

	if (!value["view"].isNull()) {
		int w = value["view"]["width"].asInt(),
			h = value["view"]["height"].asInt();
		sym->SetWidth(w);
		sym->SetHeight(h);
		sym->GetAnchorMgr().OnViewChanged(w, h);
		ChangeWindowViewSizeSJ::Instance()->Change(w, h);
	}

	std::string dir = ee::FileHelper::GetFileDir(filepath) + "\\";
	LoadSprites(value, sym, dir);
	LoadRefs(value, sym, dir);
}

std::string FileIO::StoreWrapper(const std::string& filepath, const std::string& name,
								 const std::vector<ee::Sprite*>& sprites)
{
	std::string dir = ee::FileHelper::GetFileDir(filepath) + "\\";

	ecomplex::Symbol wrapper_complex;
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		wrapper_complex.Add(sprites[i]);
	}
	std::string filename = filepath.substr(0, filepath.find_last_of('_'));
	std::string wrapper_path = filename + "_wrapper_complex[gen].json";
	wrapper_complex.SetFilepath(wrapper_path);
	wrapper_complex.name = name;
	ecomplex::FileStorer::Store(wrapper_path.c_str(), &wrapper_complex);

	return ee::FileHelper::GetRelativePath(dir, wrapper_path);;
}

void FileIO::LoadSprites(const Json::Value& val, Symbol* sym, const std::string& dir)
{
	AnchorMgr& anchors = sym->GetAnchorMgr();

	int idx = 0;
	Json::Value spr_val = val["sprite"][idx++];
	while (!spr_val.isNull()) {
		std::string filepath = ee::SymbolSearcher::GetSymbolPath(dir, spr_val);
		ee::Symbol* symbol = ee::SymbolMgr::Instance()->FetchSymbol(filepath);

		ee::Sprite* sprite = ee::SpriteFactory::Instance()->Create(symbol);
		sprite->Load(spr_val);
		anchors.Insert(sprite);
		sprite->Release();
		symbol->Release();

		spr_val = val["sprite"][idx++];
	}
}
<commit_msg>[FIXED] ui wnd store<commit_after>#include "FileIO.h"
#include "widget_id.h"
#include "Symbol.h"
#include "Sprite.h"
#include "ChangeWindowViewSizeSJ.h"

#include <ee/FileHelper.h>
#include <ee/SymbolSearcher.h>
#include <ee/SymbolMgr.h>
#include <ee/SpriteFactory.h>
#include <ee/FetchAllVisitor.h>

#include <easycomplex.h>

#include <fstream>

namespace eui
{
namespace window
{

void FileIO::Store(const char* filepath, const Symbol* sym)
{
	Json::Value value;

	std::string dir = ee::FileHelper::GetFileDir(filepath) + "\\";

	value["type"] = get_widget_desc(ID_WINDOW);
	value["name"] = sym->name;

	sym->GetAnchorMgr().StoreToFile(value, dir);

	value["view"]["width"] = sym->GetWidth();
	value["view"]["height"] = sym->GetHeight();

	std::vector<ee::Sprite*> sprites;
	const_cast<Symbol*>(sym)->GetAnchorMgr().Traverse(ee::FetchAllVisitor<ee::Sprite>(sprites));
	value["wrapper filepath"] = StoreWrapper(filepath, sym->name, sprites);

	StoreRefs(value, sym, dir);

	Json::StyledStreamWriter writer;
	std::locale::global(std::locale(""));
	std::ofstream fout(filepath);
	std::locale::global(std::locale("C"));	
	writer.write(fout, value);
	fout.close();
}

void FileIO::Load(const char* filepath, Symbol* sym)
{
	Json::Value value;
	Json::Reader reader;
	std::locale::global(std::locale(""));
	std::ifstream fin(filepath);
	std::locale::global(std::locale("C"));
	reader.parse(fin, value);
	fin.close();

	std::string type = value["type"].asString();
	if (!type.empty() && !is_widget(type, ID_WINDOW)) {
		return;
	}

	sym->name = value["name"].asString();

	if (!value["view"].isNull()) {
		int w = value["view"]["width"].asInt(),
			h = value["view"]["height"].asInt();
		sym->SetWidth(w);
		sym->SetHeight(h);
		sym->GetAnchorMgr().OnViewChanged(w, h);
		ChangeWindowViewSizeSJ::Instance()->Change(w, h);
	}

	std::string dir = ee::FileHelper::GetFileDir(filepath) + "\\";
	LoadSprites(value, sym, dir);
	LoadRefs(value, sym, dir);
}

std::string FileIO::StoreWrapper(const std::string& filepath, const std::string& name,
								 const std::vector<ee::Sprite*>& sprites)
{
	std::string dir = ee::FileHelper::GetFileDir(filepath) + "\\";

	ecomplex::Symbol wrapper_complex;
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		wrapper_complex.Add(sprites[i]);
	}
	std::string filename = filepath.substr(0, filepath.find_last_of('_'));
	std::string wrapper_path = filename + "_wrapper_complex[gen].json";
	wrapper_complex.SetFilepath(wrapper_path);
	wrapper_complex.name = name;
	ecomplex::FileStorer::Store(wrapper_path.c_str(), &wrapper_complex);

	return ee::FileHelper::GetRelativePath(dir, wrapper_path);
}

void FileIO::LoadSprites(const Json::Value& val, Symbol* sym, const std::string& dir)
{
	AnchorMgr& anchors = sym->GetAnchorMgr();

	int idx = 0;
	Json::Value spr_val = val["sprite"][idx++];
	while (!spr_val.isNull()) {
		std::string filepath = ee::SymbolSearcher::GetSymbolPath(dir, spr_val);
		ee::Symbol* symbol = ee::SymbolMgr::Instance()->FetchSymbol(filepath);

		ee::Sprite* sprite = ee::SpriteFactory::Instance()->Create(symbol);
		sprite->Load(spr_val);
		anchors.Insert(sprite);
		sprite->Release();
		symbol->Release();

		spr_val = val["sprite"][idx++];
	}
}

{'fraction_non_alphanumeric': 0.20018885741265344, 'fraction_numerical': 0.0009442870632672333, 'mean_word_length': 6.48527679623086, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2629917', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2310, 'n_words': 393}