Module: StormLib

Defined in:
lib/stormlib.rb,
ext/stormlib/stormlib.c

Defined Under Namespace

Classes: Archive

Class Method Summary collapse

Class Method Details

.add_file(handle, filename, archived_name, flags) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'ext/stormlib/stormlib.c', line 40

static VALUE rb_SFileAddFileEx(VALUE self, VALUE handle, VALUE filename, VALUE archived_name, VALUE flags) {
  HANDLE hMpq = (HANDLE)NUM2ULONG(handle);
  const char* szFileName = StringValueCStr(filename);
  const char* szArchivedName = StringValueCStr(archived_name);
  DWORD dwFlags = NUM2ULONG(flags);

  if (SFileAddFileEx(hMpq, szFileName, szArchivedName, dwFlags, MPQ_COMPRESSION_ZLIB, MPQ_COMPRESSION_NEXT_SAME)) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}

.close_archive(handle) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'ext/stormlib/stormlib.c', line 30

static VALUE rb_SFileCloseArchive(VALUE self, VALUE handle) {
  HANDLE hMpq = (HANDLE)NUM2ULONG(handle);

  if (SFileCloseArchive(hMpq)) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}

.create_archive(filename, flags, max_file_count) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'ext/stormlib/stormlib.c', line 4

static VALUE rb_SFileCreateArchive(VALUE self, VALUE filename, VALUE flags, VALUE max_file_count) {
  HANDLE hMpq;
  const char* szFileName = StringValueCStr(filename);
  DWORD dwFlags = NUM2ULONG(flags);
  DWORD dwMaxFileCount = NUM2ULONG(max_file_count);

  if (SFileCreateArchive(szFileName, dwFlags, dwMaxFileCount, &hMpq)) {
    return ULONG2NUM((uintptr_t)hMpq);
  } else {
    rb_raise(rb_eRuntimeError, "Failed to create archive");
  }
}

.extract_file(handle, archived_name, filename) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'ext/stormlib/stormlib.c', line 53

static VALUE rb_SFileExtractFile(VALUE self, VALUE handle, VALUE archived_name, VALUE filename) {
  HANDLE hMpq = (HANDLE)NUM2ULONG(handle);
  const char* szArchivedName = StringValueCStr(archived_name);
  const char* szFileName = StringValueCStr(filename);

  if (SFileExtractFile(hMpq, szArchivedName, szFileName, SFILE_OPEN_FROM_MPQ)) {
    return Qtrue;
  } else {
    return Qfalse;
  }
}

.list_files(handle) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/stormlib/stormlib.c', line 65

static VALUE rb_SFileListFiles(VALUE self, VALUE handle) {
  HANDLE hMpq = (HANDLE)NUM2ULONG(handle);
  SFILE_FIND_DATA findFileData;
  HANDLE hFind;
  VALUE fileList = rb_ary_new();

  hFind = SFileFindFirstFile(hMpq, "*", &findFileData, NULL);
  if (hFind != NULL) {
    do {
      rb_ary_push(fileList, rb_str_new_cstr(findFileData.cFileName));
    } while (SFileFindNextFile(hFind, &findFileData));

    SFileFindClose(hFind);
  }

  return fileList;
}

.open_archive(filename, priority, flags) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'ext/stormlib/stormlib.c', line 17

static VALUE rb_SFileOpenArchive(VALUE self, VALUE filename, VALUE priority, VALUE flags) {
  HANDLE hMpq;
  const char* szFileName = StringValueCStr(filename);
  DWORD dwPriority = NUM2ULONG(priority);
  DWORD dwFlags = NUM2ULONG(flags);

  if (SFileOpenArchive(szFileName, dwPriority, dwFlags, &hMpq)) {
    return ULONG2NUM((uintptr_t)hMpq);
  } else {
    rb_raise(rb_eRuntimeError, "Failed to open archive");
  }
}