wow_dbc 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e4f7517b04352b878923798bcff55dc7bdfacb73b314fae1daf16bf3ede9574
4
- data.tar.gz: 5cbbf02b3e37a9fdd1e8ad1a8c9b471ff73e6eb658cd7a38207e7e1f68386852
3
+ metadata.gz: d97e3a9ff0c814efdda99fb2aeff09817bc21aa077689fbbf22acfd6b8763f8f
4
+ data.tar.gz: 511e65038e0cc9859ed761b4f9abace4d74deeaac7dd9775088988853b3d4224
5
5
  SHA512:
6
- metadata.gz: 98f2574fb77720fc4aed8655f9efdd3eea1116dfff9103be1628adb32961eaabcac13f652331083274dd8fe249e2015a5752efd4d87d01db89efc25c5d805338
7
- data.tar.gz: f4865eac2f7d5c12b1d5c800651ced0a8983432f35a807b317a81cde7985565ad5c1a12de33a0d60116ba9eaf0f59931bc1cc8f1c9ffcc5da6551df429e460e8
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]}"
@@ -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);
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WowDBC
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wow_dbc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sebi