Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
add stormlib package + example
Browse files Browse the repository at this point in the history
  • Loading branch information
wheybags committed Jul 17, 2017
1 parent 00d70c6 commit f535169
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/configs/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ hunter_config(RapidXML VERSION 1.13)
hunter_config(SDL2 VERSION 2.0.4-p2)
hunter_config(SQLite3 VERSION autoconf-3080803) #R-Tree enabled
hunter_config(Sober VERSION 0.1.3)
hunter_config(stormlib VERSION 9.21-p1)
hunter_config(Sugar VERSION 1.2.2)
hunter_config(SuiteSparse VERSION 4.5.1-p0)
hunter_config(TIFF VERSION 4.0.2-p3)
Expand Down
27 changes: 27 additions & 0 deletions cmake/projects/stormlib/hunter.cmake
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)
14 changes: 14 additions & 0 deletions examples/stormlib/CMakeLists.txt
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)
65 changes: 65 additions & 0 deletions examples/stormlib/main.cpp
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;
}

0 comments on commit f535169

Please sign in to comment.