Newer
Older
restamp / src / main / java / osm / surveyor / matchtime / AppParameters.java
@haya4 haya4 on 26 Jan 2020 3 KB 不要なアイテムを削除
  1. package osm.surveyor.matchtime;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.util.Properties;
  9.  
  10. @SuppressWarnings("serial")
  11. public class AppParameters extends Properties {
  12. static final String FILE_PATH = "AdjustTime.ini";
  13.  
  14. // GPX: ファイル更新時刻 yyyy:MM:dd HH:mm:ss
  15. public static String IMG_TIME = "IMG.TIME";
  16.  
  17. // 対象IMGフォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ)
  18. public static String IMG_SOURCE_FOLDER = "IMG.SOURCE_FOLDER";
  19.  
  20. // 基準時刻画像(正確な撮影時刻が判明できる画像)
  21. public static String IMG_BASE_FILE = "IMG.BASE_FILE";
  22.  
  23. // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ)
  24. public static String IMG_OUTPUT_FOLDER = "IMG.OUTPUT_FOLDER";
  25.  
  26. // 出力OverwriteToSource: 入力ファイルに上書きする {ON | OFF}
  27. public static String OUTPUT_OVERWRITE_TO_SOURCE= "IMG.OUTPUT_OVERWRITE_TO_SOURCE";
  28.  
  29. File file;
  30.  
  31. public AppParameters() throws FileNotFoundException, IOException {
  32. super();
  33. this.file = new File(FILE_PATH);
  34. syncFile();
  35. }
  36.  
  37. public AppParameters(Properties defaults) throws FileNotFoundException, IOException {
  38. super(defaults);
  39. this.file = new File(FILE_PATH);
  40. syncFile();
  41. }
  42.  
  43. public AppParameters(String iniFileName) throws FileNotFoundException, IOException {
  44. super();
  45. this.file = new File(iniFileName);
  46. syncFile();
  47. }
  48.  
  49. private void syncFile() throws FileNotFoundException, IOException {
  50. boolean update = false;
  51.  
  52. if (this.file.exists()) {
  53. // ファイルが存在すれば、その内容をロードする。
  54. this.load(new FileInputStream(file));
  55. }
  56. else {
  57. update = true;
  58. }
  59.  
  60. //------------------------------------------------
  61. // 対象フォルダ:(位置情報を付加したい画像ファイルが格納されているフォルダ)
  62. String valueStr = this.getProperty(IMG_SOURCE_FOLDER);
  63. if (valueStr == null) {
  64. update = true;
  65. this.setProperty(IMG_SOURCE_FOLDER, (new File(".")).getAbsolutePath());
  66. }
  67.  
  68. //------------------------------------------------
  69. // 基準時刻画像(正確な撮影時刻が判明できる画像)
  70. valueStr = this.getProperty(IMG_BASE_FILE);
  71. if (valueStr == null) {
  72. update = true;
  73. this.setProperty(IMG_BASE_FILE, "");
  74. }
  75.  
  76. //------------------------------------------------
  77. // 出力フォルダ:(変換した画像ファイルとGPXファイルを出力するフォルダ)
  78. valueStr = this.getProperty(IMG_OUTPUT_FOLDER);
  79. if (valueStr == null) {
  80. update = true;
  81. this.setProperty(IMG_OUTPUT_FOLDER, (new File(".")).getAbsolutePath());
  82. }
  83.  
  84. //------------------------------------------------
  85. // 出力: 入力ファイルに上書きする {ON | OFF}
  86. valueStr = this.getProperty(OUTPUT_OVERWRITE_TO_SOURCE);
  87. if (valueStr == null) {
  88. update = true;
  89. this.setProperty(OUTPUT_OVERWRITE_TO_SOURCE, String.valueOf(false));
  90. }
  91.  
  92. if (update) {
  93. // ・ファイルがなければ新たに作る
  94. // ・項目が足りない時は書き足す。
  95. //this.store(new FileOutputStream(this.file), "defuilt settings");
  96. }
  97. }
  98.  
  99. public void store() throws FileNotFoundException, IOException {
  100. this.store(new FileOutputStream(this.file), "by Restamp");
  101. }
  102. }