Skip to content

Commit

Permalink
Add disabled code to convert all GCS files to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Jun 22, 2020
1 parent 808c602 commit 87b325a
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

package com.trollworks.gcs.library;

import com.trollworks.gcs.advantage.AdvantageList;
import com.trollworks.gcs.character.GURPSCharacter;
import com.trollworks.gcs.datafile.DataFile;
import com.trollworks.gcs.equipment.EquipmentList;
import com.trollworks.gcs.modifier.AdvantageModifierList;
import com.trollworks.gcs.modifier.EquipmentModifierList;
import com.trollworks.gcs.notes.NoteList;
import com.trollworks.gcs.skill.SkillList;
import com.trollworks.gcs.spell.SpellList;
import com.trollworks.gcs.template.Template;
import com.trollworks.gcs.utility.FileType;
import com.trollworks.gcs.utility.Log;
import com.trollworks.gcs.utility.PathUtils;
Expand Down Expand Up @@ -107,4 +117,47 @@ private static String getName(Object obj) {
private static boolean shouldSkip(Path path) {
return path.getFileName().toString().startsWith(".");
}

// This is here to allow quick conversion of an entire library to the latest format. By
// default, it is not called by anything. Insert it into the traverse call above where
// mCurrent.add(path) is called to go through all the files at startup.
private static void loadSave(Path path, String ext) {
try {
if (FileType.SHEET.matchExtension(ext)) {
save(new GURPSCharacter(path), path);
} else if (FileType.TEMPLATE.matchExtension(ext)) {
save(new Template(path), path);
} else if (FileType.ADVANTAGE.matchExtension(ext)) {
loadSave(new AdvantageList(), path);
} else if (FileType.ADVANTAGE_MODIFIER.matchExtension(ext)) {
loadSave(new AdvantageModifierList(), path);
} else if (FileType.EQUIPMENT.matchExtension(ext)) {
loadSave(new EquipmentList(), path);
} else if (FileType.EQUIPMENT_MODIFIER.matchExtension(ext)) {
loadSave(new EquipmentModifierList(), path);
} else if (FileType.SKILL.matchExtension(ext)) {
loadSave(new SkillList(), path);
} else if (FileType.SPELL.matchExtension(ext)) {
loadSave(new SpellList(), path);
} else if (FileType.NOTE.matchExtension(ext)) {
loadSave(new NoteList(), path);
}
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}

private static void loadSave(DataFile data, Path path) throws IOException {
data.load(path);
save(data, path);
}

private static void save(DataFile data, Path path) {
if (!data.save(path)) {
System.out.println("failed to save " + path);
System.exit(1);
}
System.out.println(path);
}
}

0 comments on commit 87b325a

Please sign in to comment.