bool DevelopmentResourceZipFile::Open()
{
	if (m_Mode != Mode::Editor)
	{
		ResourceZipFile::Open();
	}

	if (m_Mode == Mode::Editor)
	{
		// read the entire directory (all non hidden files)
		ReadAssetsDirectory(L"*");
	}

	return true;
}
bool DevelopmentResourceZipFile::VOpen(void)
{
    if (m_mode != Editor)
    {
        ResourceZipFile::VOpen();
    }

    if (m_mode == Editor)
    {
        ReadAssetsDirectory("*");
    }
    else
    {
        // TODO: FUTURE WORK - iterate through the ZipFile contents and go grab WIN32_FIND_DATA
        //   elements for each one. Then it would be possible to compare the dates/times of the
        //   asset in the Zip file with the source asset.
        throw "Not implemented!";
    }

    return true;
}
void DevelopmentResourceZipFile::ReadAssetsDirectory(std::wstring fileSpec)
{
	HANDLE fileHandle;
	WIN32_FIND_DATA findData;

	// get first file
	std::wstring pathSpec = m_AssetsDir + fileSpec;
	fileHandle = FindFirstFile(pathSpec.c_str(), &findData);

	if (fileHandle != INVALID_HANDLE_VALUE)
	{
		// loop through the remaining entries in the directory
		while (FindNextFile(fileHandle, &findData))
		{
			if (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
				continue;

			std::wstring fileName = findData.cFileName;
			if (findData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
			{
				if (fileName != L".." && fileName != L".")
				{
					fileName = fileSpec.substr(0, fileSpec.length() - 1) + fileName + L"\\*";
					ReadAssetsDirectory(fileName);
				}
			}
			else
			{
				fileName = fileSpec.substr(0, fileSpec.length() - 1) + fileName;
				std::wstring lower = fileName;
				std::transform(lower.begin(), lower.end(), lower.begin(), (int(*)(int)) std::tolower);
				wcscpy_s(&findData.cFileName[0], MAX_PATH, lower.c_str());
				m_DirectoryContentsMap[ws2s(lower)] = m_AssetFileInfo.size();
				m_AssetFileInfo.push_back(findData);
			}
		}
	}

	FindClose(fileHandle);
}
Ejemplo n.º 4
0
bool DevelopmentResourceZipFile::VOpen()
{
	if (m_mode != Editor)
	{
		ResourceZipFile::VOpen();
	}

	// open the asset directory and read in the non-hidden contents
	if (m_mode == Editor)
	{
		ReadAssetsDirectory(L"*");
	}
	else
	{
		// FUTURE WORK - iterate through the ZipFile contents and go grab WIN32_FIND_DATA 
		//   elements for each one. Then it would be possible to compare the dates/times of the
		//   asset in the Zip file with the source asset.
		GCC_ASSERT(0 && "Not implemented yet");
	}

	return true;
}
void DevelopmentResourceZipFile::ReadAssetsDirectory(std::string fileSpec)
{
#ifdef USE_WINDOWS_FS_FUNCTIONS
    HANDLE fileHandle;
    WIN32_FIND_DATA findData;

    std::string pathSpec = m_assetsDir + fileSpec;
    fileHandle = FindFirstFile(pathSpec.c_str(), &findData);

    if (fileHandle != INVALID_HANDLE_VALUE)
    {
        while (FindNextFile(fileHandle, &findData))
        {
            if (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
                continue;

            std::string fileName = findData.cFileName;
            if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
                if (fileName != ".." && fileName != ".")
                {
                    fileName = fileSpec.substr(0, fileSpec.length() - 1) + fileName + "\\*";
                    ReadAssetsDirectory(fileName);
                }
            }
            else
            {
                fileName = fileSpec.substr(0, fileSpec.length() - 1) + fileName;
	            auto lowerFileName = fileName;
                std::transform(lowerFileName.begin(), lowerFileName.end(), lowerFileName.begin(), static_cast<int(*)(int)>(std::tolower));
                //strcpy(&findData.cFileName[0], lowerFileName.c_str());
                m_directoryContentsMap[lowerFileName] = m_assetsFileInfo.size();

				FileDetails fileData;
				fileData.m_fileName = lowerFileName;
				fileData.m_fileSize = m_assetsFileInfo.size();
                m_assetsFileInfo.push_back(fileData);
            }
        }
    }
#endif

#ifdef USE_LINUX_FS_FUNCTIONS
    // TODO: Implement unix version of this method!
//    std::string pathSpec = m_assetsDir + fileSpec;
//    DIR *pDirectory = opendir(pathSpec.c_str());
//    dirent *pEntity;
//    stat st;
//
//    while((pEntity = readdir(pDirectory)) != NULL)
//    {
//        const std::string name = pEntity->d_name;
//        const std::string fullName = pathSpec + "/" + name;
//
//        if (name == ".." || name == ".")
//            continue;
//
//        if (stat(fullName.c_str(), &st) == -1)
//            continue;
//
//        if (st.st_mode & S_IFDIR)
//        {
//            ReadAssetsDirectory(fullName);
//        }
//        else
//        {
//
//        }
//    }
#endif
}