Example #1
0
size_t HashStream::ReadLineToString(HeapString& outString, bool includeNewLine/*=true*/)const
{
	size_t oldPos = outString.Length();
	size_t readCount = mSourceStream->ReadLineToString(outString, includeNewLine);
	RETURN_ZERO_IF_ZERO(readCount);

	mHasher->Process(outString.c_str() + oldPos, (outString.Length() - oldPos)*sizeof(char));
	return readCount;
}
Example #2
0
size_t HashStream::ReadStringTo(HeapString& outString)const
{
	size_t oldPos = outString.Length();
	size_t readCount = mSourceStream->ReadStringTo(outString);
	RETURN_ZERO_IF_ZERO(readCount);

	mHasher->Process(outString.c_str() + oldPos, outString.Length() - oldPos);
	return readCount;
}
Example #3
0
bool FileStorage::SearchDirectoriesToAdd(const StringRef& searchPath, DirectoryEntry* destDir /*= nullptr*/, bool recursively /*= true*/)
{
	if (destDir == nullptr)
	{
		destDir = &mRootDir;
	}
	List<HeapString> dirList;
	Directory::SearchDirectories(searchPath, dirList, recursively);
	HeapString searchDir = Path::GetDirectory(searchPath);

	for (auto& dir : dirList)
	{
		StringRef subDir;
		if (searchDir.IsEmpty())
		{
			subDir = dir;
		}
		else
		{
			subDir = dir.ToString().SubString(searchDir.Length() + 1);	//+1 to skip '/'
		}

		auto* dirEntry = FindOrCreateDirectoryEntry(subDir, destDir);
		if (dirEntry == nullptr)
		{
			Log::FormatError("Cannot create dir:{}", subDir);
			return false;
		}
		Log::FormatInfo("Add Dir:{}", dir);

	}
	return true;
}
		void Launcher::UpdateItemCount(const uint count) const
		{
			if (count == 0 || count == 1)
			{
				menu[IDM_LAUNCHER_EDIT_FIND].Enable( count );
				menu[IDM_LAUNCHER_EDIT_CLEAR].Enable( count );
			}

			static HeapString form( HeapString() << ' ' << Resource::String(IDS_TEXT_FILES) << ": " );

			const uint length = form.Length();
			statusBar.Text(StatusBar::SECOND_FIELD) << (form << count).Ptr();
			form.ShrinkTo( length );
		}
Example #5
0
void SirenTextParser::Preprocess(HeapString& text)
{
	//trim
	//remove all comment
	intp beginIndex = text.Length() - 1;
	while (true)
	{
		beginIndex = text.LastIndexOf("//", 0, beginIndex);
		if (beginIndex >= 0)
		{
			intp endIndex = text.IndexOfAny(StdString::ConstValues<char>::NewLineChars, beginIndex + 2);
			if (endIndex >= 0)
			{
				text.RemoveAt(beginIndex, endIndex - beginIndex);
			}
		}
		else
		{
			return;
		}
	}
}
Example #6
0
bool FileStorage::SearchFilesToAdd(const StringRef& searchPath, DirectoryEntry* destDir /*= nullptr*/, bool recursively /*= true*/, bool isReadonly /*= false*/, bool overwrite /*= true*/, bool deleteOriginalFile /*= false*/)
{
	SearchDirectoriesToAdd(searchPath, destDir, recursively);
	if (destDir == nullptr)
	{
		destDir = &mRootDir;
	}
	List<HeapString> fileList;
	Directory::SearchFiles(searchPath, fileList, recursively);
	HeapString searchDir = Path::GetDirectory(searchPath);

	for (const auto& file : fileList)
	{
		auto fs = File::OpenBinaryReader(file);
		if (!fs)
		{
			Log::FormatError("Cannot read file:{}", file);
			return false;
		}


		StringRef destFile;
		if (searchDir.IsEmpty())
		{
			destFile = file;
		}
		else
		{
			destFile = file.ToString().SubString(searchDir.Length() + 1);	//+1 to skip '/'
		}
		bool overwriteFile = false;
		if (overwrite)
		{
			if (RemoveFile(destFile))
			{
				overwriteFile = true;
			}
		}
		else
		{
			if (ExistsFile(destFile))
			{
				Log::FormatInfo("NOT overwrite file:{}", destFile);
				continue;
			}
		}

		auto* fileEntry = SaveFile(*fs, destFile, destDir);
		fileEntry->SetPermission(isReadonly ? FilePermission::Read : FilePermission::All);
		Log::FormatInfo("Add file:{} to {}", destFile, file);

		if (overwriteFile)
		{
			Log::FormatInfo("Overwrite file:{}", destFile);
		}
	}

	if (deleteOriginalFile)
	{
		for (const auto& file : fileList)
		{
			File::Delete(file);
		}
	}

	return true;
}