This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 652
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# cmake/projects/Example/hunter.cmake | ||
|
||
# !!! DO NOT PLACE HEADER GUARDS HERE !!! | ||
|
||
# Load used modules | ||
include(hunter_add_version) | ||
include(hunter_download) | ||
include(hunter_pick_scheme) | ||
include(hunter_cacheable) | ||
|
||
# List of versions here... | ||
hunter_add_version( | ||
PACKAGE_NAME | ||
stormlib | ||
VERSION | ||
"9.21-p1" | ||
URL | ||
"https://github.com/hunter-packages/StormLib/archive/v9.21-p1.tar.gz" | ||
SHA1 | ||
d394e375bed09100f0ae6c173a9962542d1967dc | ||
) | ||
|
||
# Pick a download scheme | ||
hunter_pick_scheme(DEFAULT url_sha1_cmake) # use scheme for cmake projects | ||
|
||
hunter_cacheable(stormlib) | ||
hunter_download(PACKAGE_NAME stormlib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
# Emulate HunterGate: | ||
# * https://github.com/hunter-packages/gate | ||
include("../common.cmake") | ||
|
||
project(example-stormlib) | ||
|
||
hunter_add_package(stormlib) | ||
|
||
find_package(stormlib CONFIG REQUIRED) | ||
|
||
add_executable(example-stormlib main.cpp) | ||
target_link_libraries(example-stormlib stormlib::stormlib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include <Stormlib.h> | ||
#include <stdio.h> | ||
|
||
int ExtractFile(char * szArchiveName, char * szArchivedFile, char * szFileName) | ||
{ | ||
HANDLE hMpq = NULL; // Open archive handle | ||
HANDLE hFile = NULL; // Archived file handle | ||
FILE* handle = NULL; // Disk file handle | ||
int nError = ERROR_SUCCESS; // Result value | ||
|
||
// Open an archive, e.g. "d2music.mpq" | ||
if(nError == ERROR_SUCCESS) | ||
{ | ||
if(!SFileOpenArchive(szArchiveName, 0, STREAM_FLAG_READ_ONLY, &hMpq)) | ||
nError = GetLastError(); | ||
} | ||
|
||
// Open a file in the archive, e.g. "data\global\music\Act1\tristram.wav" | ||
if(nError == ERROR_SUCCESS) | ||
{ | ||
if (!SFileOpenFileEx(hMpq, szArchivedFile, 0, &hFile)) | ||
nError = GetLastError(); | ||
} | ||
|
||
// Create the target file | ||
if(nError == ERROR_SUCCESS) | ||
{ | ||
handle = fopen(szFileName, "wb"); | ||
if (!handle) | ||
nError = -1; | ||
} | ||
|
||
// Read the file from the archive | ||
if(nError == ERROR_SUCCESS) | ||
{ | ||
char szBuffer[0x10000]; | ||
DWORD dwBytes = 1; | ||
|
||
while(dwBytes > 0) | ||
{ | ||
SFileReadFile(hFile, szBuffer, sizeof(szBuffer), &dwBytes, NULL); | ||
if (dwBytes > 0) | ||
fwrite(szBuffer, 1, dwBytes, handle); | ||
} | ||
} | ||
|
||
// Cleanup and exit | ||
if (handle != NULL) | ||
fclose(handle); | ||
if(hFile != NULL) | ||
SFileCloseFile(hFile); | ||
if(hMpq != NULL) | ||
SFileCloseArchive(hMpq); | ||
|
||
return nError; | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc != 4) | ||
return -1; | ||
|
||
int err = ExtractFile(argv[1], argv[2], argv[3]); | ||
return err; | ||
} |