<commit_before>/*
	newcs c vWFNg
	newcs f vWFNg
	newcs t vWFNg
	newcs d vWFNg [O]
	newcs c2 vWFNg
	newcs f2 vWFNg
	newcs t2 vWFNg
	newcs d2 vWFNg [O]
	newcs tt vWFNg

	newcs
	newcs /r

	newcs /d
	newcs /dr
*/

#include "C:\Factory\Common\all.h"
#include "C:\Factory\Common\Options\CRandom.h"

#define TESTER_PROJ_LOCALDIR "Test01"

static uint UTIntoParentStep;

static char *FindUserTemplate(void)
{
	char *dir = getCwd();

	for(; ; )
	{
		char *tmplDir = combine(dir, "Template");
		char *tmplSln;

		tmplSln = combine(tmplDir, "UUUUTMPL.sln");

		if(existFile(tmplSln))
		{
			memFree(dir);
			memFree(tmplSln);

			cout("User_Template: %s\n", tmplDir);

			return tmplDir;
		}
		memFree(tmplDir);
		memFree(tmplSln);

		dir = changeLocal_xc(dir, "");

		errorCase(strlen(dir) == 2);

		UTIntoParentStep++;
	}
	error(); // never
	return NULL;
}
static void RenamePaths(char *fromPtn, char *toPtn)
{
	autoList_t *paths = ls(".");
	char *path;
	char *nPath;
	uint dirCount;
	uint index;

	eraseParents(paths);
	dirCount = lastDirCount;

	foreach(paths, path, index)
	{
		if(index < dirCount)
		{
			addCwd(path);
			{
				RenamePaths(fromPtn, toPtn);
			}
			unaddCwd();
		}
		nPath = replaceLine(strx(path), fromPtn, toPtn, 1);

		if(replaceLine_getLastReplacedCount())
		{
			coExecute_x(xcout("REN \"%s\" \"%s\"", path, nPath));
		}
		memFree(nPath);
	}
	releaseDim(paths, 1);
}
static void ChangeAppIdent(char *srcFile)
{
	char *src = readText(srcFile);
	char *p;
	char *q;
	char *uuid;

	p = strstrNext(src, "public const string APP_IDENT = \"");
	errorCase(!p);
	q = strstr(p, "\";");
	errorCase(!q);
	errorCase((uint)q - (uint)p != 38); // {} t UUID ̒

	uuid = MakeUUID(1);

	memcpy(p, uuid, 38);

	writeOneLineNoRet(srcFile, src);

	memFree(src);
	memFree(uuid);
}
static void ResolveRelHintPath(char *file)
{
	char *text = readText_b(file);
	char *p;
	int modified = 0;

	text = strrm(text, 128000000); // XXX
	p = text;

	while(p = strstrNext(p, "<HintPath>"))
	{
		if(startsWith(p, "..\\"))
		{
			char *trailer = strx(p);
			uint c;

			for(c = 0; c < UTIntoParentStep; c++)
			{
				*p++ = '.';
				*p++ = '.';
				*p++ = '\\';
			}
			strcpy(p, trailer);

			memFree(trailer);

			p = strstrNext(p, "</HintPath>");
			errorCase(!p);

			modified = 1;
		}
	}
	if(modified)
		writeOneLineNoRet_b(file, text);

	memFree(text);
}
static void Main2(char *tmplProject, char *tmplDir, int utFlag, int m2Flag, char *tmplProjNS)
{
	char *project = nextArg();
	char *projNS;

	if(hasArgs(1))
		projNS = nextArg();
	else
		projNS = project;

	errorCase(!existDir(tmplDir)); // 2bs ?

	errorCase_m(!lineExp("<1,30,__09AZaz>", project), "sȃvWFNgłB");
	errorCase_m(existPath(project), "ɑ݂܂B");

	createDir(project);
	copyDir(tmplDir, project);

	addCwd(project);
	{
		coExecute("qq -f");

		RenamePaths(tmplProject, project);

		if(tmplProjNS)
			RenamePaths(tmplProjNS,  projNS);

		addCwd(existDir(TESTER_PROJ_LOCALDIR) ? TESTER_PROJ_LOCALDIR : project);
		{
			ChangeAppIdent("Program.cs");

			if(utFlag)
			{
				char *csprojFile = xcout("%s.csproj", project);

				if(existFile(csprojFile))
				{
					ResolveRelHintPath(csprojFile);
				}
				memFree(csprojFile);
			}
		}
		unaddCwd();

		removeFileIfExist("C:\\Factory\\tmp\\Sections.txt"); // Ӑ}Ȃʂ trep Ȃ悤ɁAÔߌʂNA

		coExecute_x(xcout("Search.exe %s", tmplProject));
		coExecute_x(xcout("trep.exe /F %s", project));

		if(tmplProjNS)
		{
			coExecute_x(xcout("Search.exe %s", tmplProjNS));
			coExecute_x(xcout("trep.exe /F %s", projNS));
		}

//		execute("START .");

		execute_x(xcout("%s.sln", project));

		if(m2Flag)
			execute("START C:\\Dev\\CSharp\\Module2\\Module2");
	}
	unaddCwd();
}
static uint64 GetChocolateSourceLeastStamp(void)
{
	autoList_t *files = lssFiles("C:\\Dev\\CSharp\\Chocolate\\Chocolate");
	char *file;
	uint index;
	uint64 leastStamp = 0;

	foreach(files, file, index)
	{
		uint64 stamp;

		if(mbs_stristr(file, "\\bin\\")) // bin ̔z͏O
			continue;

		if(mbs_stristr(file, "\\obj\\")) // obj ̔z͏O
			continue;

		getFileStamp(file, NULL, NULL, &stamp);

		m_maxim(leastStamp, stamp);
	}
	return leastStamp;
}
static int IsChocolateSourceUpdated(void)
{
	uint64 dllStamp;
	uint64 leastStamp = GetChocolateSourceLeastStamp();
<commit_msg>Fontaine<commit_after>/*
	newcs c vWFNg
	newcs f vWFNg
	newcs t vWFNg
	newcs d vWFNg [O]
	newcs c2 vWFNg
	newcs f2 vWFNg
	newcs t2 vWFNg
	newcs d2 vWFNg [O]
	newcs tt vWFNg

	newcs
	newcs /r

	newcs /d
	newcs /dr
*/

#include "C:\Factory\Common\all.h"
#include "C:\Factory\Common\Options\CRandom.h"

#define TESTER_PROJ_LOCALDIR "Test01"

static uint UTIntoParentStep;

static char *FindUserTemplate(void)
{
	char *dir = getCwd();

	for(; ; )
	{
		char *tmplDir = combine(dir, "Template");
		char *tmplSln;

		tmplSln = combine(tmplDir, "UUUUTMPL.sln");

		if(existFile(tmplSln))
		{
			memFree(dir);
			memFree(tmplSln);

			cout("User_Template: %s\n", tmplDir);

			return tmplDir;
		}
		memFree(tmplDir);
		memFree(tmplSln);

		dir = changeLocal_xc(dir, "");

		errorCase(strlen(dir) == 2);

		UTIntoParentStep++;
	}
	error(); // never
	return NULL;
}
static void RenamePaths(char *fromPtn, char *toPtn)
{
	autoList_t *paths = ls(".");
	char *path;
	char *nPath;
	uint dirCount;
	uint index;

	eraseParents(paths);
	dirCount = lastDirCount;

	foreach(paths, path, index)
	{
		if(index < dirCount)
		{
			addCwd(path);
			{
				RenamePaths(fromPtn, toPtn);
			}
			unaddCwd();
		}
		nPath = replaceLine(strx(path), fromPtn, toPtn, 1);

		if(replaceLine_getLastReplacedCount())
		{
			coExecute_x(xcout("REN \"%s\" \"%s\"", path, nPath));
		}
		memFree(nPath);
	}
	releaseDim(paths, 1);
}
static void ChangeAppIdent(char *srcFile)
{
	char *src = readText(srcFile);
	char *p;
	char *q;
	char *uuid;

	p = strstrNext(src, "public const string APP_IDENT = \"");
	errorCase(!p);
	q = strstr(p, "\";");
	errorCase(!q);
	errorCase((uint)q - (uint)p != 38); // {} t UUID ̒

	uuid = MakeUUID(1);

	memcpy(p, uuid, 38);

	writeOneLineNoRet(srcFile, src);

	memFree(src);
	memFree(uuid);
}
static void ResolveRelHintPath(char *file)
{
	char *text = readText_b(file);
	char *p;
	int modified = 0;

	text = strrm(text, 128000000); // XXX
	p = text;

	while(p = strstrNext(p, "<HintPath>"))
	{
		if(startsWith(p, "..\\"))
		{
			char *trailer = strx(p);
			uint c;

			for(c = 0; c < UTIntoParentStep; c++)
			{
				*p++ = '.';
				*p++ = '.';
				*p++ = '\\';
			}
			strcpy(p, trailer);

			memFree(trailer);

			p = strstrNext(p, "</HintPath>");
			errorCase(!p);

			modified = 1;
		}
	}
	if(modified)
		writeOneLineNoRet_b(file, text);

	memFree(text);
}
static void Main2(char *tmplProject, char *tmplDir, int utFlag, int m2Flag, char *tmplProjNS)
{
	char *project = nextArg();
	char *projNS;

	if(hasArgs(1))
		projNS = nextArg();
	else
		projNS = project;

	errorCase(!existDir(tmplDir)); // 2bs ?

	errorCase_m(!lineExp("<1,30,__09AZaz>", project), "sȃvWFNgłB");
	errorCase_m(existPath(project), "ɑ݂܂B");

	createDir(project);
	copyDir(tmplDir, project);

	addCwd(project);
	{
		coExecute("qq -f");

		RenamePaths(tmplProject, project);

		if(tmplProjNS)
			RenamePaths(tmplProjNS,  projNS);

		addCwd(existDir(TESTER_PROJ_LOCALDIR) ? TESTER_PROJ_LOCALDIR : project);
		{
			ChangeAppIdent("Program.cs");

			if(utFlag)
			{
				char *csprojFile = xcout("%s.csproj", project);

				if(existFile(csprojFile))
				{
					ResolveRelHintPath(csprojFile);
				}
				memFree(csprojFile);
			}
		}
		unaddCwd();

		removeFileIfExist("C:\\Factory\\tmp\\Sections.txt"); // Ӑ}Ȃʂ trep Ȃ悤ɁAÔߌʂNA

		coExecute_x(xcout("Search.exe %s", tmplProject));
		coExecute_x(xcout("trep.exe /F %s", project));

		if(tmplProjNS)
		{
			coExecute_x(xcout("Search.exe %s", tmplProjNS));
			coExecute_x(xcout("trep.exe /F %s", projNS));
		}

//		execute("START .");

		execute_x(xcout("%s.sln", project));

		if(m2Flag)
			execute("START C:\\Dev\\CSharp\\Module2");
//			execute("START C:\\Dev\\CSharp\\Module2\\Module2"); // del @ 2020.5.23
	}
	unaddCwd();
}
static uint64 GetChocolateSourceLeastStamp(void)
{
	autoList_t *files = lssFiles("C:\\Dev\\CSharp\\Chocolate\\Chocolate");
	char *file;
	uint index;
	uint64 leastStamp = 0;

	foreach(files, file, index)
	{
		uint64 stamp;

		if(mbs_stristr(file, "\\bin\\")) // bin ̔z͏O
			continue;

		if(mbs_stristr(file, "\\obj\\")) // obj ̔z͏O
			continue;

		getFileStamp(file, NULL, NULL, &stamp);

		m_maxim(leastStamp, stamp);
	}
	return leastStamp;
}
static int IsChocolateSourceUpdated(void)
{
	uint64 dllStamp;
	uint64 leastStamp = GetChocolateSourceLeastStamp();

{'fraction_non_alphanumeric': 0.1732440685929058, 'fraction_numerical': 0.012450082217524078, 'mean_word_length': 3.8053047404063207, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '1597836', 'n_tokens_mistral': 4099, 'n_tokens_neox': 3647, 'n_words': 674}