wow_dbc 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/ext/wow_dbc/wow_dbc.c +34 -0
- data/lib/wow_dbc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d97e3a9ff0c814efdda99fb2aeff09817bc21aa077689fbbf22acfd6b8763f8f
|
4
|
+
data.tar.gz: 511e65038e0cc9859ed761b4f9abace4d74deeaac7dd9775088988853b3d4224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cd53cb380048db472a1c294a36d0cb80631a7860409e3d1fdd1be4738096ae9a7a0547d5bb928bb19266d3461c6b6f21136805a60a235a92c07b3e5eeabd8f8
|
7
|
+
data.tar.gz: 75fb5d97eb1091a7dd40812e35f01b5c30283e1d520a7db0c8d70a1ea549aa403a36b9c62fc637a0afcba65cc909ee2157dede9886602d84127320b51fe7d636
|
data/README.md
CHANGED
@@ -78,9 +78,12 @@ puts "Newly created item: #{new_item}"
|
|
78
78
|
# Delete an item (be careful with this!)
|
79
79
|
# dbc.delete_record(new_item_index)
|
80
80
|
|
81
|
-
# Write changes back to the file
|
81
|
+
# Write changes back to the same file(update)
|
82
82
|
dbc.write
|
83
83
|
|
84
|
+
# Write to a new file
|
85
|
+
dbc.write_to('path/to/your/NewItem.dbc')
|
86
|
+
|
84
87
|
# Reading header information
|
85
88
|
header = dbc.header
|
86
89
|
puts "Total items: #{header[:record_count]}"
|
data/ext/wow_dbc/wow_dbc.c
CHANGED
@@ -344,6 +344,39 @@ static VALUE dbc_find_by(VALUE self, VALUE field, VALUE value) {
|
|
344
344
|
return result;
|
345
345
|
}
|
346
346
|
|
347
|
+
static VALUE dbc_write_to(VALUE self, VALUE new_filepath) {
|
348
|
+
DBCFile *dbc;
|
349
|
+
TypedData_Get_Struct(self, DBCFile, &dbc_data_type, dbc);
|
350
|
+
|
351
|
+
Check_Type(new_filepath, T_STRING);
|
352
|
+
const char *path = StringValueCStr(new_filepath);
|
353
|
+
|
354
|
+
FILE *file = fopen(path, "wb");
|
355
|
+
if (!file) {
|
356
|
+
rb_raise(rb_eIOError, "Could not open file for writing: %s", path);
|
357
|
+
}
|
358
|
+
|
359
|
+
if (fwrite(&dbc->header, sizeof(DBCHeader), 1, file) != 1) {
|
360
|
+
fclose(file);
|
361
|
+
rb_raise(rb_eIOError, "Failed to write DBC header");
|
362
|
+
}
|
363
|
+
|
364
|
+
for (uint32_t i = 0; i < dbc->header.record_count; i++) {
|
365
|
+
if (fwrite(dbc->records[i], sizeof(uint32_t), dbc->header.field_count, file) != dbc->header.field_count) {
|
366
|
+
fclose(file);
|
367
|
+
rb_raise(rb_eIOError, "Failed to write DBC record");
|
368
|
+
}
|
369
|
+
}
|
370
|
+
|
371
|
+
if (fwrite(dbc->string_block, 1, dbc->header.string_block_size, file) != dbc->header.string_block_size) {
|
372
|
+
fclose(file);
|
373
|
+
rb_raise(rb_eIOError, "Failed to write DBC string block");
|
374
|
+
}
|
375
|
+
|
376
|
+
fclose(file);
|
377
|
+
return self;
|
378
|
+
}
|
379
|
+
|
347
380
|
void Init_wow_dbc(void) {
|
348
381
|
rb_mWowDBC = rb_define_module("WowDBC");
|
349
382
|
rb_cDBCFile = rb_define_class_under(rb_mWowDBC, "DBCFile", rb_cObject);
|
@@ -351,6 +384,7 @@ void Init_wow_dbc(void) {
|
|
351
384
|
rb_define_method(rb_cDBCFile, "initialize", dbc_initialize, 2);
|
352
385
|
rb_define_method(rb_cDBCFile, "read", dbc_read, 0);
|
353
386
|
rb_define_method(rb_cDBCFile, "write", dbc_write, 0);
|
387
|
+
rb_define_method(rb_cDBCFile, "write_to", dbc_write_to, 1);
|
354
388
|
rb_define_method(rb_cDBCFile, "create_record", dbc_create_record, 0);
|
355
389
|
rb_define_method(rb_cDBCFile, "create_record_with_values", dbc_create_record_with_values, 1);
|
356
390
|
rb_define_method(rb_cDBCFile, "update_record", dbc_update_record, 3);
|
data/lib/wow_dbc/version.rb
CHANGED