Ejemplo n.º 1
0
static int TestOpenStorage_OpenFile(const TCHAR * szStorage, const char * szFileName)
{
	HANDLE hStorage;
	HANDLE hFile;
	DWORD dwBytesRead;
	BYTE Buffer[0x1000];
	int nError = ERROR_SUCCESS;

	// Open the storage directory
	if(!CascOpenStorage(szStorage, 0, &hStorage))
	{
		assert(GetLastError() != ERROR_SUCCESS);
		nError = GetLastError();
	}

	DWORD dwFileCount = 0;
	if(CascGetStorageInfo(hStorage, CascStorageFileCount, &dwFileCount, sizeof(DWORD), NULL))
	{
		printf("file count: %d\n", dwFileCount);
	}

	DWORD dwFeatures = 0;
	if(CascGetStorageInfo(hStorage, CascStorageFeatures, &dwFeatures, sizeof(DWORD), NULL))
	{
		printf("support listfile? %s\n", (dwFeatures & CASC_FEATURE_LISTFILE) ? "YES" : "NO");
	}

	if(nError == ERROR_SUCCESS)
	{
		// Open a file
		if(!CascOpenFile(hStorage, szFileName, CASC_LOCALE_ZHCN, 0, &hFile))
		{
			assert(GetLastError() != ERROR_SUCCESS);
			nError = GetLastError();
		}
	}

	// Read some data from the file
	if(nError == ERROR_SUCCESS)
	{
		DWORD dwFileSize, dwFileSizeHigh;
		dwFileSize = CascGetFileSize(hFile, &dwFileSizeHigh);
		printf("file name : %s, file size: %d\n", szFileName, dwFileSize);

		// Read data from the file
		CascReadFile(hFile, Buffer, sizeof(Buffer), &dwBytesRead);
		CascCloseFile(hFile);
	}

	// Close storage and return
	if(hStorage != NULL)
		CascCloseStorage(hStorage);
	return nError;
}
Ejemplo n.º 2
0
bool OpenCascStorage()
{
    if (!CascOpenStorage("Data", 0, &CascStorage))
    {
        printf("Error %d\n", GetLastError());
        return false;
    }

    printf("\n");
    return true;
}
Ejemplo n.º 3
0
static int TestOpenStorage_EnumFiles(const TCHAR * szStorage, const TCHAR * szListFile = NULL)
{
    CASC_FIND_DATA FindData;
    HANDLE hStorage;
    HANDLE hFind;
    DWORD dwTotalFiles = 0;
    DWORD dwFoundFiles = 0;
    bool bFileFound = true;
    int nError = ERROR_SUCCESS;

    // Open the storage directory
    if(!CascOpenStorage(szStorage, 0, &hStorage))
    {
        assert(GetLastError() != ERROR_SUCCESS);
        nError = GetLastError();
    }

    if(nError == ERROR_SUCCESS)
    {
        // Retrieve the total number of files
        CascGetStorageInfo(hStorage, CascStorageFileCount, &dwTotalFiles, sizeof(dwTotalFiles), NULL);

        // Start finding
        hFind = CascFindFirstFile(hStorage, "*", &FindData, szListFile);
        if(hFind != NULL)
        {
            while(bFileFound)
            {
                // Extract the file
//              printf("%s\n", FindData.szFileName);
                dwFoundFiles++;

                // Find the next file in CASC
                bFileFound = CascFindNextFile(hFind, &FindData);
            }

            // Just a testing call - must fail
            CascFindNextFile(hFind, &FindData);

            // Close the search handle
            CascFindClose(hFind);
        }
    }

    // Close storage and return
    if(hStorage != NULL)
        CascCloseStorage(hStorage);
    return nError;
}
Ejemplo n.º 4
0
bool OpenCascStorage(int locale)
{
    try
    {
        boost::filesystem::path const storage_dir(boost::filesystem::canonical(input_path) / "Data");
        if (!CascOpenStorage(storage_dir.string().c_str(), WowLocaleToCascLocaleFlags[locale], &CascStorage))
        {
            printf("error opening casc storage '%s' locale %s: %s\n", storage_dir.string().c_str(), localeNames[locale], HumanReadableCASCError(GetLastError()));
            return false;
        }
        printf("opened casc storage '%s' locale %s\n", storage_dir.string().c_str(), localeNames[locale]);
        return true;
    }
    catch (boost::filesystem::filesystem_error& error)
    {
        printf("error opening casc storage : %s\n", error.what());
        return false;
    }
}
Ejemplo n.º 5
0
static int TestOpenStorage_EnumFiles(const TCHAR * szStorage, const TCHAR * szListFile)
{
	CASC_FIND_DATA FindData;
	HANDLE hStorage;
	HANDLE hFind;
	bool bFileFound = true;
	int nError = ERROR_SUCCESS;

	// Open the storage directory
	if(!CascOpenStorage(szStorage, 0, &hStorage))
	{
		assert(GetLastError() != ERROR_SUCCESS);
		nError = GetLastError();
	}

	if(nError == ERROR_SUCCESS)
	{
		hFind = CascFindFirstFile(hStorage, "*", &FindData, szListFile);
		if(hFind != NULL)
		{
			while(bFileFound)
			{
				// Extract the file
				 printf("%s\n", FindData.szFileName);

				// Find the next file in CASC
				bFileFound = CascFindNextFile(hFind, &FindData);
			}

			// Just a testing call - must fail
			CascFindNextFile(hFind, &FindData);

			// Close the search handle
			CascFindClose(hFind);
		}
	}

	// Close storage and return
	if(hStorage != NULL)
		CascCloseStorage(hStorage);
	return nError;
}
Ejemplo n.º 6
0
static int TestOpenStorage_ExtractFiles(const TCHAR * szStorage, const TCHAR * szTargetDir, const TCHAR * szListFile)
{
    CASC_FIND_DATA FindData;
    HANDLE hStorage;
    HANDLE hFind;
    bool bFileFound = true;
    int nError = ERROR_SUCCESS;

    // Open the storage directory
    if(!CascOpenStorage(szStorage, 0, &hStorage))
    {
        assert(GetLastError() != ERROR_SUCCESS);
        nError = GetLastError();
    }

    if(nError == ERROR_SUCCESS)
    {
        hFind = CascFindFirstFile(hStorage, "*", &FindData, szListFile);
        if(hFind != INVALID_HANDLE_VALUE)
        {
            while(bFileFound)
            {
                // Extract the file
                printf("Extracting: %s ...", FindData.szFileName);
                nError = ExtractFile(hStorage, FindData.szFileName, szTargetDir, FindData.dwLocaleFlags);
                printf((nError == ERROR_SUCCESS) ? "OK\n" : "Failed\n");

                // Find the next file in CASC
                bFileFound = CascFindNextFile(hFind, &FindData);
            }

            // Close the search handle
            CascFindClose(hFind);
        }
    }

    // Close storage and return
    if(hStorage != NULL)
        CascCloseStorage(hStorage);
    return nError;
}
Ejemplo n.º 7
0
static int TestOpenStorage_OpenFile(const TCHAR * szStorage, const char * szFileName)
{
    HANDLE hStorage;
    HANDLE hFile;
    DWORD dwBytesRead;
    BYTE Buffer[0x1000];
    int nError = ERROR_SUCCESS;

    // Open the storage directory
    if(!CascOpenStorage(szStorage, 0, &hStorage))
    {
        assert(GetLastError() != ERROR_SUCCESS);
        nError = GetLastError();
    }

    if(nError == ERROR_SUCCESS)
    {
        // Open a file
        if(!CascOpenFile(hStorage, szFileName, 0, 0, &hFile))
        {
            assert(GetLastError() != ERROR_SUCCESS);
            nError = GetLastError();
        }
    }

    // Read some data from the file
    if(nError == ERROR_SUCCESS)
    {
        // Read data from the file
        CascReadFile(hFile, Buffer, sizeof(Buffer), &dwBytesRead);
        CascCloseFile(hFile);
    }

    // Close storage and return
    if(hStorage != NULL)
        CascCloseStorage(hStorage);
    return nError;
}