Пример #1
0
//============================================================================
//		NFileUtilities::SetFileText : Set a file to text.
//----------------------------------------------------------------------------
NStatus NFileUtilities::SetFileText(const NFile &theFile, const NString &theText, NStringEncoding theEncoding, NStringRendering renderAs)
{


	// Set the file text
	return(SetFileData(theFile, theText.GetData(theEncoding, renderAs)));
}
Пример #2
0
bool GetFileInfo(const AString& FileName, FILE_INFO *file)
{
	struct dirent ent;

	strcpy(ent.d_name, FileName.FilePart());

	return SetFileData(FileName.PathPart(), ent, file);
}
Пример #3
0
bool TitleSequenceAddPark(TitleSequence* seq, const utf8* path, const utf8* name)
{
    // Get new save index
    size_t index = SIZE_MAX;
    for (size_t i = 0; i < seq->NumSaves; i++)
    {
        if (String::Equals(seq->Saves[i], path, true))
        {
            index = i;
            break;
        }
    }
    if (index == SIZE_MAX)
    {
        seq->Saves = Memory::ReallocateArray(seq->Saves, seq->NumSaves + 1);
        Guard::Assert(seq->Saves != nullptr, GUARD_LINE);
        index = seq->NumSaves;
        seq->NumSaves++;
    }
    seq->Saves[index] = String::Duplicate(name);

    if (seq->IsZip)
    {
        try
        {
            auto fdata = File::ReadAllBytes(path);
            auto zip = Zip::TryOpen(seq->Path, ZIP_ACCESS::WRITE);
            if (zip == nullptr)
            {
                Console::Error::WriteLine("Unable to open '%s'", seq->Path);
                return false;
            }
            zip->SetFileData(name, std::move(fdata));
        }
        catch (const std::exception& ex)
        {
            Console::Error::WriteLine(ex.what());
        }
    }
    else
    {
        // Determine destination path
        utf8 dstPath[MAX_PATH];
        String::Set(dstPath, sizeof(dstPath), seq->Path);
        Path::Append(dstPath, sizeof(dstPath), name);
        if (!File::Copy(path, dstPath, true))
        {
            Console::Error::WriteLine("Unable to copy '%s' to '%s'", path, dstPath);
            return false;
        }
    }
    return true;
}
Пример #4
0
bool GetFileInfo(const AString& FileName, FILE_INFO *file)
{
	WIN32_FIND_DATA finddata;
	HANDLE handle;
	bool ok = false;

	if ((handle = ::FindFirstFile(FileName, &finddata)) != INVALID_HANDLE_VALUE) {
		if (file) {
			SetFileData(FileName.PathPart(), finddata, file);
		}

		::FindClose(handle);

		ok = true;
	}

	return ok;
}
Пример #5
0
bool Recurse(const AString& Path, const AString& Pattern, uint_t nSubDirs, bool (*fn)(const FILE_INFO *file, void *Context), void *Context)
{
	AString   pattern = ParsePathRegex(Pattern);
	FILE_INFO file;
	DIR		  *handle;
	bool      ok = true, any = IsRegexAnyPattern(pattern);

	if ((handle = opendir(Path.Valid() ? Path : ".")) != NULL) {
		struct dirent *ent;

		while (ok && ((ent = readdir(handle)) != NULL)) {
			if (SetFileData(Path, *ent, &file)) {
				if ((file.ShortName != ".") && (file.ShortName != "..")) {
					bool done = false;

					if (any || MatchPathRegex(file.ShortName, pattern)) {
						ok = (*fn)(&file, Context);
						if (!ok) break;
						done = true;
					}
					if ((nSubDirs > 0) && (file.Attrib & FILE_FLAG_IS_DIR)) {
						if (!done) {
							ok = (*fn)(&file, Context);
							if (!ok) break;
						}
						
						ok = Recurse(file.FileName, Pattern, nSubDirs - 1, fn, Context);
						if (!ok) break;
					}
				}
			}
		}

		closedir(handle);
	}

	return ok;
}
Пример #6
0
bool Recurse(const AString& Path, const AString& Pattern, uint_t nSubDirs, bool (*fn)(const FILE_INFO *file, void *Context), void *Context)
{
	WIN32_FIND_DATA finddata;
	AString   pattern, pattern1 = ParsePathRegex(Pattern);
	FILE_INFO file;
	HANDLE    handle;
	bool      ok = true, any = IsRegexAnyPattern(pattern1);

	pattern = Path.CatPath("*");
	if ((handle = ::FindFirstFile(pattern, &finddata)) != INVALID_HANDLE_VALUE) {
		do {
			SetFileData(Path, finddata, &file);

			if ((file.ShortName != ".") && (file.ShortName != "..")) {
				bool done = false;

				if (any || MatchPathRegex(file.ShortName, pattern1)) {
					ok = (*fn)(&file, Context);
					if (!ok) break;
					done = true;
				}
				if ((nSubDirs > 0) && (file.Attrib & FILE_FLAG_IS_DIR)) {
					if (!done) {
						ok = (*fn)(&file, Context);
						if (!ok) break;
					}

					ok = Recurse(file.FileName, Pattern, nSubDirs - 1, fn, Context);
					if (!ok) break;
				}
			}
		} while (ok && ::FindNextFile(handle, &finddata));

		::FindClose(handle);
	}

	return ok;
}
Пример #7
0
bool TitleSequenceSave(TitleSequence* seq)
{
    try
    {
        auto script = LegacyScriptWrite(seq);
        if (seq->IsZip)
        {
            auto fdata = std::vector<uint8_t>(script.begin(), script.end());
            auto zip = Zip::Open(seq->Path, ZIP_ACCESS::WRITE);
            zip->SetFileData("script.txt", std::move(fdata));
        }
        else
        {
            auto scriptPath = Path::Combine(seq->Path, "script.txt");
            File::WriteAllBytes(scriptPath, script.data(), script.size());
        }
        return true;
    }
    catch (const std::exception&)
    {
        return false;
    }
}
Пример #8
0
HRESULT CCommands::XApplicationEvents::BeforeBuildStart()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	IApplication* pApplication;

	pApplication = m_pCommands->GetApplicationObject();

	CComPtr<IProjects> pIProjects = NULL;
	pApplication->get_Projects((IDispatch **)&pIProjects);

	long					lProjects			= 0;
	CComVariant				varProject			;
	VERIFY_OK( pIProjects->get_Count( &lProjects ) );

	for ( long lProject = 1 ; lProject < lProjects + 1 ; lProject++ )
	{
		varProject = lProject;

		CComPtr< IGenericProject > pIGenericProject;

		VERIFY_OK( pIProjects->Item(varProject, &pIGenericProject));

		if (pIGenericProject)
		{
			CComBSTR bType;
			CString strType;
			pIGenericProject->get_Type(&bType);
			strType = bType;
			if (strType.CompareNoCase(DS_BUILD_PROJECT) != 0) continue;

			CComBSTR bStr;
			pIGenericProject->get_FullName(&bStr);

			CString strProjectName = bStr;
			CString strProjectPath, strRcName, strConfigName;
			UINT uSvnVersion = 0;

			TCHAR sDrive[_MAX_DRIVE] = {0};
			TCHAR sDir[_MAX_DIR] = {0};
			TCHAR sFname[_MAX_FNAME] = {0};
			TCHAR sExt[_MAX_EXT] = {0};

			_tsplitpath(strProjectName, sDrive, sDir, sFname, sExt);

			strProjectPath = CString(sDrive) + CString(sDir);
			strConfigName = CString(sDrive) + CString(sDir) + CString(sFname) + CString(_T(".ini"));

			// 得到配置信息
			CONFIG config;
			COptionDlg::GetConfig(config, strConfigName);

			if (config.bCheckSvn && !config.bCheckSelfUpdata)
			{
				// const svn_version_t *ver = svn_wc_version();
				uSvnVersion = GetWorkSvnVersion(strProjectPath, config.iSvnVersionPath);

				if (uSvnVersion == 0)
				{
					return S_OK;
				}
			}

			CString Data;

			GetFileData(strProjectName, Data);

			if (Data.IsEmpty())
			{
				return S_OK;
			}

			strRcName = GetRegexpData(Data, _T("SOURCE=(?<SCR>.+\\.rc)$|SOURCE=\"(?<SCR>.+\\.rc)\""), MULTILINE | IGNORECASE, "SCR");

			if (strRcName.IsEmpty())
			{
				return S_OK;
			}

			CString strFileVersion, strFileVersionDescribe, strVersion, strVersionDescribe, RcData;
			UINT uFileVer[4], uFileVerDesc[4];
			BOOL bUpdata = FALSE;

			GetFileData(strProjectPath + strRcName, RcData);

			if (RcData.IsEmpty())
			{
				return S_OK;
			}

			// 进行 版本信息 更新
			strVersion = GetRegexpData(RcData, _T(".+VALUE.+\"FileVersion\",.+\"(.+)\""), MULTILINE | IGNORECASE);
			if (!strVersion.IsEmpty())
			{
				sscanf(strVersion, "%d, %d, %d, %d", &uFileVer[0], &uFileVer[1], &uFileVer[2], &uFileVer[3]);
				UpdataVersionInfo(uFileVer, config, uSvnVersion);
				strFileVersion.Format(_T("$1%d, %d, %d, %d\\0$2"),
					uFileVer[0], uFileVer[1], uFileVer[2], uFileVer[3]);

				if (-1 == strFileVersion.Find(strVersion))
				{
					RcData = ReplaceRegexpData(
						RcData,
						_T("(.+VALUE.+\"FileVersion\",.+\").+(\")"),
						MULTILINE | IGNORECASE,
						strFileVersion);
					bUpdata = TRUE;
				}
			}

			strVersion = GetRegexpData(RcData, _T(".+VALUE.+\"ProductVersion\",.+\"(.+)\""), MULTILINE | IGNORECASE);
			if (!strVersion.IsEmpty())
			{
				sscanf(strVersion, "%d, %d, %d, %d", &uFileVer[0], &uFileVer[1], &uFileVer[2], &uFileVer[3]);
				UpdataVersionInfo(uFileVer, config, uSvnVersion);
				strFileVersion.Format(_T("$1%d, %d, %d, %d\\0$2"),
					uFileVer[0], uFileVer[1], uFileVer[2], uFileVer[3]);

				if (-1 == strFileVersion.Find(strVersion))
				{
					RcData = ReplaceRegexpData(
						RcData,
						_T("(.+VALUE.+\"ProductVersion\",.+\").+(\")"),
						MULTILINE | IGNORECASE,
						strFileVersion);
					bUpdata = TRUE;
				}
			}

			strVersionDescribe = GetRegexpData(RcData, _T(".+FILEVERSION[ ]+(.+)"), MULTILINE | IGNORECASE);
			if (!strVersionDescribe.IsEmpty())
			{
				sscanf(strVersionDescribe, "%d,%d,%d,%d", &uFileVerDesc[0], &uFileVerDesc[1], &uFileVerDesc[2], &uFileVerDesc[3]);
				UpdataVersionInfo(uFileVerDesc, config, uSvnVersion);
				strFileVersionDescribe.Format(_T("$1%d,%d,%d,%d"),
					uFileVerDesc[0], uFileVerDesc[1], uFileVerDesc[2], uFileVerDesc[3]);

				if (-1 == strFileVersionDescribe.Find(strVersionDescribe))
				{
					RcData = ReplaceRegexpData(
						RcData,
						_T("(.+FILEVERSION[ ]+).+"),
						MULTILINE | IGNORECASE,
						strFileVersionDescribe);
					bUpdata = TRUE;
				}
			}

			strVersionDescribe = GetRegexpData(RcData, _T(".+ProductVersion[ ]+(.+)"), MULTILINE | IGNORECASE);
			if (!strVersionDescribe.IsEmpty())
			{
				sscanf(strVersionDescribe, "%d,%d,%d,%d", &uFileVerDesc[0], &uFileVerDesc[1], &uFileVerDesc[2], &uFileVerDesc[3]);
				UpdataVersionInfo(uFileVerDesc, config, uSvnVersion);
				strFileVersionDescribe.Format(_T("$1%d,%d,%d,%d"),
					uFileVerDesc[0], uFileVerDesc[1], uFileVerDesc[2], uFileVerDesc[3]);

				if (-1 == strFileVersionDescribe.Find(strVersionDescribe))
				{
					RcData = ReplaceRegexpData(
						RcData,
						_T("(.+ProductVersion[ ]+).+"),
						MULTILINE | IGNORECASE,
						strFileVersionDescribe);
					bUpdata = TRUE;
				}
			}

			if (bUpdata)
			{
				SetFileData(strProjectPath + strRcName, RcData);
			}
		}
	}

	return S_OK;
}