Settings.java
     1: //========================================================================================
     2: //  Settings.java
     3: //    en:Settings
     4: //    ja:設定
     5: //  Copyright (C) 2003-2024 Makoto Kamada
     6: //
     7: //  This file is part of the XEiJ (X68000 Emulator in Java).
     8: //  You can use, modify and redistribute the XEiJ if the conditions are met.
     9: //  Read the XEiJ License for more details.
    10: //  https://stdkmd.net/xeij/
    11: //========================================================================================
    12: 
    13: //----------------------------------------------------------------------------------------
    14: //
    15: //  設定ファイル
    16: //    XEiJの動作環境を指示する「設定」が1つ以上記述されているファイル
    17: //    場所
    18: //      Windowsのとき(os.nameがWindowsを含むとき)
    19: //        %APPDATA%\XEiJ\XEiJ.ini    C:\Users\%USERNAME%\AppData\Roaming\XEiJ\XEiJ.iniなど。%~%は環境変数
    20: //      その他
    21: //        ~/XEiJ.ini                 ~はuser.home
    22: //        ./XEiJ.ini                 .はuser.dir
    23: //    内容
    24: //      [タイトルA]
    25: //      キーワードA1=値A1
    26: //      キーワードA2=値A2
    27: //          :
    28: //      [タイトルB]
    29: //      キーワードB1=値B1
    30: //      キーワードB2=値B2
    31: //          :
    32: //
    33: //  設定の種類
    34: //    設定にはデフォルト設定とユーザ設定がある
    35: //    デフォルト設定(default)
    36: //      タイトルがdefaultの設定
    37: //      プログラムに埋め込まれている定数にhomeとlangを加えたもの
    38: //      デフォルト設定にないキーワードは指定できない
    39: //      デフォルト設定と同じ値のパラメータは保存されない
    40: //    ユーザ設定
    41: //      タイトルがdefault以外の設定
    42: //      saveonexit=onのとき設定ファイルに保存される
    43: //      無題設定と仮設定とその他のユーザ設定がある
    44: //      無題設定(notitle)
    45: //        [notitle]のユーザ設定
    46: //        起動時にユーザ設定が1つもないときデフォルト設定が無題設定にコピーされて現在の設定になる
    47: //        自動で作られることを除けば普通のユーザ設定
    48: //        設定ファイルの先頭に配置される
    49: //        設定ファイルの最初の設定が無題設定のとき[notitle]を省略できる
    50: //      仮設定(temporary)
    51: //        [temporary]のユーザ設定
    52: //        -config=defaultを指定するとデフォルト設定が仮設定にコピーされて現在の設定になる
    53: //        -config=defaultを指定するとデフォルト設定に巻き戻されるので常用は避けた方が良い
    54: //        設定ファイルの無題設定の後に配置される
    55: //      その他のユーザ設定
    56: //        設定ファイルの無題設定と仮設定の後に配置される
    57: //        その他のユーザ設定の順序はユーザが自由に並べ替えることができる
    58: //
    59: //  パラメータ
    60: //    設定ファイル
    61: //      キーワード=値
    62: //      1行に1組ずつ書く
    63: //      キーワードと値の前後に余分な空白があってはならない
    64: //    コマンドライン
    65: //      -キーワード=値
    66: //      1引数に1組ずつ書く
    67: //      キーワードと値の前後に余分な空白があってはならない
    68: //    キーワード
    69: //      英小文字で始まり英小文字と数字で構成される文字列
    70: //    値
    71: //      空白以外で始まり空白以外で終わる文字列
    72: //      空列または空白を含む文字列は"~"で囲む
    73: //      デフォルト設定で値がonまたはoffのパラメータはonまたはoffだけ指定できる
    74: //      デフォルト設定で値がyesまたはnoのパラメータはyesまたはnoだけ指定できる
    75: //      デフォルト設定で値が符号と数字だけのパラメータは符号と数字だけ指定できる
    76: //      キーワードがdataで終わるパラメータ
    77: //        値がgzip+base64で圧縮されている
    78: //        値が非常に大きい場合があり、原則として文字列の状態では編集できない
    79: //        バイナリデータとして編集する機能を付けてもよい
    80: //
    81: //  デフォルト設定で環境に合わせて作られるパラメータ
    82: //    home=path
    83: //      ホームディレクトリ。末尾の区切り文字は含まない
    84: //      ファイルチューザーが最初に開くディレクトリ
    85: //    lang=en
    86: //    lang=ja
    87: //      表示言語
    88: //
    89: //  設定ファイルの特別なパラメータ
    90: //    [タイトル]
    91: //      新しい設定の開始。設定のタイトル
    92: //      []、[default]は不可
    93: //      -config=タイトルで設定を選択するときに使う
    94: //      タイトルが同じ設定が複数存在してはならない
    95: //      改行を含むことはできない
    96: //      [、]を除く文字は何でも書けるが、"、'、`、$などはコマンドラインで選択するときに書きにくいので避けた方が良い
    97: //      設定ファイルの最初の設定が無題設定のとき[notitle]を省略できる
    98: //    current=yes
    99: //    current=no
   100: //      現在の設定かどうか
   101: //      current=yesのユーザ設定が1つだけ存在する
   102: //    description=説明
   103: //      設定の説明
   104: //
   105: //  コマンドラインの特別なパラメータ
   106: //    -config=~はコマンドラインの最後に書いても他のパラメータよりも優先して解釈される
   107: //    -config=default
   108: //      デフォルト設定が仮設定にコピーされて現在の設定になる
   109: //      一時的にデフォルト設定で起動したいときに使う
   110: //      他のパラメータはデフォルト設定がコピーされた仮設定に上書きされる
   111: //      仮設定は-config=defaultを指定すると消えてしまうので、仮設定の常用は避けた方が良い
   112: //      仮設定以外の設定はcurrent=yesがcurrent=noになるものを除いて変化しない。すべての設定が初期化されるわけではない
   113: //    -config=タイトル
   114: //      タイトルで選択されたユーザ設定(無題設定、仮設定を含む)が現在の設定になる
   115: //      他のパラメータは選択されたユーザ設定に上書きされる
   116: //
   117: //  その他の特筆すべきパラメータ
   118: //    saveonexit=on
   119: //    saveonexit=off
   120: //      終了時に設定ファイルを更新するかどうか
   121: //      現在の設定がsaveonexit=offのとき終了時に設定ファイルが更新されない
   122: //      設定ファイルにエラーがあったとき
   123: //        設定ファイルを更新してしまうとエラーの箇所やそれ以降に書かれていた内容が消えてしまう恐れがある
   124: //        現在の設定がsaveonexit=onでも終了時に設定ファイルを更新せず手動で修正することを促す
   125: //
   126: //----------------------------------------------------------------------------------------
   127: 
   128: package xeij;
   129: 
   130: import java.awt.*;  //BasicStroke,BorderLayout,BoxLayout,Color,Component,Container,Cursor,Desktop,Dimension,Font,Frame,Graphics,Graphics2D,GraphicsDevice,GraphicsEnvironment,GridLayout,Image,Insets,Paint,Point,Rectangle,RenderingHints,Robot,Shape,Stroke,TexturePaint,Toolkit
   131: import java.awt.event.*;  //ActionEvent,ActionListener,ComponentAdapter,ComponentEvent,ComponentListener,FocusAdapter,FocusEvent,FocusListener,InputEvent,KeyAdapter,KeyEvent,KeyListener,MouseAdapter,MouseEvent,MouseListener,MouseMotionAdapter,MouseWheelEvent,WindowAdapter,WindowEvent,WindowListener,WindowStateListener
   132: import java.io.*;  //BufferedInputStream,BufferedOutputStream,BufferedReader,BufferedWriter,File,FileInputStream,FileNotFoundException,FileReader,InputStream,InputStreamReader,IOException,OutputStreamWriter,RandomAccessFile
   133: import java.lang.*;  //Boolean,Character,Class,Comparable,Double,Exception,Float,IllegalArgumentException,Integer,Long,Math,Number,Object,Runnable,SecurityException,String,StringBuilder,System
   134: import java.net.*;  //MalformedURLException,URI,URL
   135: import java.util.*;  //ArrayList,Arrays,Calendar,GregorianCalendar,HashMap,Map,Map.Entry,Timer,TimerTask,TreeMap
   136: import java.util.regex.*;  //Matcher,Pattern
   137: //import javax.jnlp.*;  //BasicService,PersistenceService,ServiceManager,UnavailableServiceException
   138: import javax.swing.*;  //AbstractSpinnerModel,Box,ButtonGroup,DefaultListModel,ImageIcon,JButton,JCheckBox,JCheckBoxMenuItem,JDialog,JFileChooser,JFrame,JLabel,JList,JMenu,JMenuBar,JMenuItem,JPanel,JRadioButton,JScrollPane,JSpinner,JTextArea,JTextField,JTextPane,JViewport,ScrollPaneConstants,SpinnerListModel,SpinnerNumberModel,SwingConstants,SwingUtilities,UIManager,UIDefaults,UnsupportedLookAndFeelException
   139: import javax.swing.event.*;  //CaretListener,ChangeEvent,ChangeListener,DocumentEvent,DocumentListener,ListSelectionListener
   140: import netscape.javascript.*;  //JSException,JSObject。jfxrt.jarではなくplugin.jarを使うこと
   141: 
   142: public class Settings {
   143: 
   144:   //RestorableFrameのキーの一覧
   145:   //  ウインドウの位置とサイズ(~rect)、状態(~stat)、開くかどうか(~open)のパラメータで使う
   146:   public static final String SGS_ACM_FRAME_KEY = "acm";  //ACM アドレス変換キャッシュモニタ
   147:   public static final String SGS_ATW_FRAME_KEY = "atw";  //ATW 論理空間モニタ
   148:   public static final String SGS_BLG_FRAME_KEY = "blg";  //BLG 分岐ログ
   149:   public static final String SGS_DBP_FRAME_KEY = "dbp";  //DBP データブレークポイント
   150:   public static final String SGS_DDP_FRAME_KEY = "ddp";  //DDP 逆アセンブルリスト
   151:   public static final String SGS_DGT_FRAME_KEY = "dgt";  //DGT コンソールウインドウ
   152:   public static final String SGS_DMP_FRAME_KEY = "dmp";  //DMP メモリダンプリスト
   153:   public static final String SGS_DRP_FRAME_KEY = "drp";  //DRP レジスタ
   154:   public static final String SGS_FNT_FRAME_KEY = "fnt";  //FNT フォントエディタ
   155:   public static final String SGS_FRM_FRAME_KEY = "frm";  //FRM メインウインドウ
   156:   public static final String SGS_GRS_FRAME_KEY = "grs";
   157:   public static final String SGS_GSA_FRAME_KEY = "gsa";
   158:   public static final String SGS_KBS_FRAME_KEY = "kbs";  //KBS キーボード設定
   159:   public static final String SGS_OLG_FRAME_KEY = "olg";  //OLG OPMログ
   160:   public static final String SGS_PAA_FRAME_KEY = "paa";  //PAA 物理空間モニタ
   161:   public static final String SGS_PFF_FRAME_KEY = "pff";  //PFF プロファイリング
   162:   public static final String SGS_PFV_FRAME_KEY = "pfv";  //PFV プログラムフロービジュアライザ
   163:   public static final String SGS_PPI_FRAME_KEY = "ppi";  //PPI ジョイスティック
   164:   public static final String SGS_PRN_FRAME_KEY = "prn";  //PRN プリンタ
   165:   public static final String SGS_RBP_FRAME_KEY = "rbp";  //RBP ラスタブレークポイント
   166:   public static final String SGS_RTL_FRAME_KEY = "rtl";  //RTL ルートポインタリスト
   167:   public static final String SGS_SMN_FRAME_KEY = "smn";  //SMN 音声モニタ
   168:   public static final String SGS_SMT_FRAME_KEY = "smt";  //SMT 表示モードテスト
   169:   public static final String SGS_SPV_FRAME_KEY = "spv";  //SPV スプライトパターンビュア
   170:   public static final String SGS_TRM_FRAME_KEY = "trm";  //TRM ターミナル
   171:   public static final String[] SGS_FRAME_KEYS = {
   172:     SGS_ACM_FRAME_KEY,
   173:     SGS_ATW_FRAME_KEY,
   174:     SGS_BLG_FRAME_KEY,
   175:     SGS_DBP_FRAME_KEY,
   176:     SGS_DDP_FRAME_KEY,
   177:     SGS_DGT_FRAME_KEY,
   178:     SGS_DMP_FRAME_KEY,
   179:     SGS_DRP_FRAME_KEY,
   180:     SGS_FNT_FRAME_KEY,
   181:     SGS_FRM_FRAME_KEY,
   182:     SGS_GRS_FRAME_KEY,
   183:     SGS_GSA_FRAME_KEY,
   184:     SGS_KBS_FRAME_KEY,
   185:     SGS_OLG_FRAME_KEY,
   186:     SGS_PAA_FRAME_KEY,
   187:     SGS_PFF_FRAME_KEY,
   188:     SGS_PFV_FRAME_KEY,
   189:     SGS_PPI_FRAME_KEY,
   190:     SGS_PRN_FRAME_KEY,
   191:     SGS_RBP_FRAME_KEY,
   192:     SGS_RTL_FRAME_KEY,
   193:     SGS_SMN_FRAME_KEY,
   194:     SGS_SMT_FRAME_KEY,
   195:     SGS_SPV_FRAME_KEY,
   196:     SGS_TRM_FRAME_KEY,
   197:   };
   198: 
   199:   //デフォルト設定のベース
   200:   //  キーワードと値の配列
   201:   //  キーワードはnullではない。値もnullではない
   202:   //  キーワードは""ではない。値が""のときは指定されていないものとみなす
   203:   //  デフォルト設定で値がonまたはoffのパラメータはonまたはoffだけ指定できる
   204:   //  デフォルト設定で値がyesまたはnoのパラメータはyesまたはnoだけ指定できる
   205:   //  デフォルト設定で値が符号と数字だけのパラメータは符号と数字だけ指定できる
   206:   //      キーワードがdataで終わるパラメータ
   207:   //        値がgzip+base64で圧縮されている
   208: 
   209:   public static final String SGS_DEFAULT_PARAMETERS = (
   210:     //PRG
   211:     "verbose;on;" +  //冗長表示(on/off)
   212:     //SGS
   213:     //"_;;" +  //この設定の設定名。ここには書かない
   214:     "saveonexit;on;" +  //終了時に設定を保存(on/off)
   215:     "config;;" +  //復元する設定の設定名。パラメータで指定する。設定ファイルには出力しない
   216:     "lang;en;" +  //言語(en/ja)。初期値は動作環境の言語
   217:     "home;;" +  //ホームディレクトリ。初期値は動作環境のホームディレクトリ
   218:     "dir;;" +  //カレントディレクトリ。初期値は動作環境のカレントディレクトリ
   219:     //LNF
   220:     "hhssbb;667,667,700,300,0,1000;" +  //色
   221:     //KBD
   222:     "keyboard;standard;" +  //キーボードの種類(none,standard,compact)
   223:     "keymapus;off;" +  //USレイアウト(on/off)
   224:     "keymap;;" +  //Zキーボード以外のキーマップ
   225:     "f11key;fullscreen;" +  //F11キー(fullscreen/screenshot/gifanimation/stopandstart/donothing)
   226:     "zkeyboard;off;" +  //Zキーボード(on/off)
   227:     "zkeymap;;" +  //Zキーボードのキーマップ
   228:     //GIF
   229:     "gifwaitingtime;;" +  //GIFアニメーション録画の待ち時間(s)
   230:     "gifrecordingtime;10;" +  //GIFアニメーション録画の録画時間(s)
   231:     "gifmagnification;100;" +  //GIFアニメーション録画の倍率(%)
   232:     "gifinterpolation;bilinear;" +  //アニメーション録画の補間アルゴリズム(nearest,bilinear,bicubic)
   233:     //PNL
   234:     "scaling;fitinwindow;" +  //画面スケーリングモード(fullscreen,fitinwindow,fixedscale)
   235:     "fixedscale;100;" +  //固定倍率
   236:     "aspectratio256x256;4:3;" +  //アスペクト比256x256
   237:     "aspectratio384x256;4:3;" +  //アスペクト比384x256
   238:     "aspectratio512x512;4:3;" +  //アスペクト比512x512
   239:     "aspectratio768x512;3:2;" +  //アスペクト比768x512
   240:     "interpolation;bilinear;" +  //補間アルゴリズム(nearest,bilinear,bicubic)
   241:     //MUS
   242:     "seamless;on;" +  //シームレス/エクスクルーシブ(on/off)
   243:     "ctrlright;off;" +  //Ctrlキー+左ボタンを右ボタンとみなす(on/off)
   244:     "edgeaccel;off;" +  //縁部加速
   245:     "mousespeed;;" +  //マウスカーソルの速度(0~40)
   246:     "hostspixelunits;off;" +  //ホストの画素単位で動く(on/off)
   247:     "mousewheel;trace;" +  //ホイールの機能(trace/click/donothing)
   248:     //MDL
   249:     "model;Hybrid;" +  //機種(Shodai|ACE|EXPERT|PRO|SUPER|XVI|Xellent30|Compact|Hybrid|X68030|030Compact|060turbo)
   250:     "mpu;none;" +  //MPUの種類(-1=機種に従う/0=MC68000/1=MC68010/3=MC68EC030/6=MC68060)
   251:     "clock;none;" +  //MPUの動作周波数(-1=機種に従う,1..1000,Shodai,ACE,EXPERT,PRO,SUPER,XVI,Xellent30,Compact,Hybrid,X68030,030Compact,060turbo,060turboPRO)
   252:     "mhz;200;" +  //任意の周波数(1~1000)。任意の負荷率がonのときの周波数のスピナーの値
   253:     "util;off;" +  //任意の負荷率(on/off)
   254:     "ratio;100;" +  //任意の負荷率(1~100)
   255:     "waitcycles;on;" +  //ウェイトサイクル(on/off)
   256:     //FPU
   257:     "fpumode;1;" +  //FPUモード(0=なし/1=拡張精度/2=三倍精度)
   258:     "fullspecfpu;off;" +  //フルスペックFPU(on/off)
   259:     //FPK
   260:     "fefunc;on;" +  //FEファンクション命令(on/off)
   261:     "rejectfloat;off;" +  //FLOATn.Xを組み込まない(on/off)
   262:     //BUS
   263:     "highmemory;;" +  //X68030のハイメモリのサイズ(MB)(0/16)
   264:     "highmemorysave;off;" +  //X68030のハイメモリの内容を保存する(on/off)
   265:     "highmemorydata;;" +  //X68030のハイメモリの内容(gzip+base64)
   266:     "highmemory060turbo;off;" +  //060turboのローカルメモリを使う(on/off)
   267:     "localmemory;128;" +  //060turboのローカルメモリのサイズ(MB)(0/16/32/64/128/256)
   268:     "localmemorysave;off;" +  //060turboのローカルメモリの内容を保存する(on/off)
   269:     "localmemorydata;;" +  //060turboのローカルメモリの内容(gzip+base64)
   270:     "cutfc2pin;off;" +  //FC2ピンをカットする(on/off)
   271:     //MMR
   272:     "memory;12;" +  //メインメモリのサイズ(0/1/2/4/6/8/10/12)。0は既定値
   273:     "memorysave;on;" +  //メインメモリの内容を保存する(on/off)
   274:     "memorydata;;" +  //メインメモリの内容(gzip+base64)
   275:     //CON
   276:     "pastepipe;off;" +  //貼り付けパイプを使う(on/off)
   277:     //CRT
   278:     "intermittent;0;" +  //間欠描画(0~4)
   279:     "stereoscopic;off;" +  //立体視(on/off)
   280:     "stereoscopicmethod;nakedeyecrossing;" +  //立体視の方法(nakedeyecrossing/nakedeyeparallel/sidebyside/topandbottom)
   281:     "extendedgraphic;off;" +  //拡張グラフィック画面(on/off)
   282:     "scanline;medium;" + //走査線エフェクト(off/weak/medium/strong/black)
   283:     "dotclock;,,;" +  //ドットクロックオシレータ(low,high,vga)
   284:     "eleventhbit;off;" +  //1024ドットノンインターレース(on/off)
   285:     "sphericalscrolling;off;" +  //球面スクロール(on/off)
   286:     "r00bit0zero;off;" +  //CRTC R00のビット0(on/off)
   287:     //SPR
   288:     "sprras;32;" +  //ラスタあたりのスプライトの枚数(0~256)
   289:     "dblspr;off;" +  //スプライト256枚(on/off)
   290:     //SND
   291:     "sound;on;" +  //音声出力(on/off)
   292:     "volume;20;" +  //ボリューム(0~40)
   293:     "soundinterpolation;linear;" +  //音声補間(thinning/linear/constant-area/linear-area)
   294:     //OPM
   295:     "opmoutput;on;" +  //OPM出力
   296:     //PCM
   297:     "pcmoutput;on;" +  //PCM出力
   298:     "pcminterpolation;linear;" +  //PCM補間(constant/linear/hermite)
   299:     "pcmoscfreq;0;" +  //PCM原発振周波数(0=8MHz/4MHz,1=8MHz/16MHz)
   300:     //FDC
   301:     //  ユニットとヒストリは後で設定する
   302:     "fdreadonly;off;" +  //書き込み禁止(on/off)
   303:     "fdappreboot;off;" +  //ここから再起動(on/off)
   304:     //HDC
   305:     //  ユニットとヒストリは後で設定する
   306:     "sareadonly;off;" +  //書き込み禁止(on/off)
   307:     "saappreboot;off;" +  //ここから再起動(on/off)
   308:     //SPC
   309:     //  ユニットとヒストリは後で設定する
   310:     "screadonly;off;" +  //SCSI HDを書き込み禁止で開く(on/off)
   311:     "scappreboot;off;" +  //ここから再起動(on/off)
   312:     //HFS
   313:     //  ユニットとヒストリは後で設定する
   314:     "hfreadonly;off;" +  //書き込み禁止(on/off)
   315:     "hfappreboot;off;" +  //ここから再起動(on/off)
   316:     "utf8warning;off;" +  //HFSで開いたファイルがUTF-8のとき警告する
   317:     //PPI
   318:     "joykey;on;" +  //キーボードの一部をジョイスティックとみなす
   319:     "joyauto;on;" +  //ジョイスティックポートが連続的に読み出されている間だけ有効
   320:     "joyblock;on;" +  //ジョイスティック入力データとして処理されたキーボード入力データを取り除く
   321:     "normal2button1;;" +  //ノーマル2ボタンパッド#1の設定
   322:     "normal2button2;;" +  //ノーマル2ボタンパッド#2の設定
   323:     "megadrive3button1;;" +  //メガドラ3ボタンパッド#1の設定
   324:     "megadrive3button2;;" +  //メガドラ3ボタンパッド#2の設定
   325:     "megadrive6button1;;" +  //メガドラ6ボタンパッド#1の設定
   326:     "megadrive6button2;;" +  //メガドラ6ボタンパッド#2の設定
   327:     "cyberstickdigital1;;" +  //サイバースティック(デジタルモード)#1の設定
   328:     "cyberstickdigital2;;" +  //サイバースティック(デジタルモード)#2の設定
   329:     "cyberstickanalog1;;" +  //サイバースティック(アナログモード)#1の設定
   330:     "cyberstickanalog2;;" +  //サイバースティック(アナログモード)#2の設定
   331:     "shiromadokun1;;" +  //白窓君1の仕様
   332:     "shiromadokun2;;" +  //白窓君2の仕様
   333:     "joystick1;normal2button1;" +  //ジョイスティックポート1に接続するデバイス
   334:     "joystick2;normal2button2;" +  //ジョイスティックポート2に接続するデバイス
   335:     "joyportukun;off;" +  //じょいぽーとU君(on/off)
   336:     "ukunmode;notifya;" +  //じょいぽーとU君のモード(notifya/notifyb/command)
   337:     "ukunjsc;off;" +  //じょいぽーとU君でjSerialCommを使う(on/off)
   338:     "ukuninterval;off;" +  //じょいぽーとU君で出力間隔調整を行う(on/off)
   339:     "xinput;off;" +  //XInput(on/off)
   340:     //EXS
   341:     "scsiex;off;" +  //on=拡張SCSIポートを有効にする
   342:     //SMR
   343:     "boot;default;" +  //起動デバイス(default/std/fdN/hdN/scN/hfN/rom$X/ram$X)
   344:     "keydly;-1;" +  //リピートディレイ(-1=既定/200+100*n)
   345:     "keyrep;-1;" +  //リピートインターバル(-1=既定/30+5*n^2)
   346:     "sram;none;" +  //SRAMイメージファイル名
   347:     "sramdata;;" +  //SRAMの内容(gzip+base64)
   348:     "sramsize;16;" +  //SRAMの容量(16/32/64)
   349:     "romdb;off;" +  //ROMデバッガ起動フラグ
   350:     "modifymemorysize;on;" +  //SRAMにあるメモリサイズを修正する
   351:     "srambuserror;off;" +  //SRAMへの書き込み時のバスエラー
   352:     //BNK
   353:     "bankdata;;" +  //バンクメモリの内容(gzip+base64)
   354:     //ROM
   355:     "rom;none;" +  //ROMのイメージファイル名
   356:     "cgrom;none;" + //CGROMのイメージファイル名
   357:     "rom30;none;" +  //X68030のIPLROMのイメージファイル名
   358:     "scsiinrom;none;" +  //SCSIINROMのイメージファイル名
   359:     "scsiexrom;none;" +  //SCSIEXROMのイメージファイル名
   360:     "iplrom;none;" +  //IPLROMのイメージファイル名
   361:     "iplrom256k;off;" +  //X68000のIPLROMを256KBに改造する
   362:     "iplrom16;off;" +  //IPLROM 1.6を使う
   363:     "omusubi;off;" +  //おむすびフォントを使う
   364:     //PRN
   365:     "prnauto;off;" +  //自動保存
   366:     "prnpath;printer;" +  //ディレクトリ
   367:     "prndipsw;;" +  //ディップスイッチ
   368:     "prnsize;A4;" +  //用紙のサイズ
   369:     "prnorientation;portrait;" +  //用紙の方向
   370:     "prntopmargin;11;" +  //印字不可領域
   371:     "prnleftmargin;14;" +
   372:     "prnrightmargin;14;" +
   373:     "prnbottommargin;11;" +
   374:     "prnrotation;;" +  //回転
   375:     "prndarkmode;off;" +  //ダークモード
   376:     "prnonline;on;" +  //オンライン
   377:     "prnsinglecolor;;" +  //単色インクリボンの色
   378:     "prnscalefactor;;" +  //表示倍率
   379:     //SCC
   380:     "sccfreq;5000000;" +  //SCCの動作周波数
   381:     //TRM
   382:     "rs232cconnection;Terminal+%E2%87%94+AUX;" +  //接続。textをURLEncoderにかけて/で連結
   383:     "terminalsettings;38400/B8/PN/S1/RTS;" +  //ターミナルの通信設定。38400などを/で連結
   384:     //XT3
   385:     "xt3dipsw;3;" +  //Xellent30のDIPSW(0~3)
   386:     "xt3memorykb;256;" +  //Xellent30のメモリのサイズ(256/1024)
   387:     "xt3memorydata;;" +  //Xellent30のメモリの内容(gzip+base64)
   388:     "xt3memorysave;off;"  //Xellent30のメモリの保存フラグ(on/off)
   389:     );
   390: 
   391:   public static final String SGS_APPDATA_FOLDER = "XEiJ";  //Windowsのみ。AppData/Roamingフォルダに掘るフォルダの名前
   392:   public static final String SGS_INI = "XEiJ.ini";  //設定ファイル名
   393: 
   394:   public static final Pattern SGS_BOOT_DEVICE_PATTERN = Pattern.compile ("^(?:default|std|(?:fd|hd|sc|hf)\\d+|r[oa]m\\$[0-9A-Fa-f]+)$", Pattern.CASE_INSENSITIVE);  //-bootに指定できる起動デバイス名
   395: 
   396:   public static String sgsAppDataRoamingFolder;  //Windowsのみ。AppData/Roamingフォルダ。1人のユーザが複数のPCで同期して利用できるファイルを入れる
   397:   public static String sgsAppDataLocalFolder;  //Windowsのみ。AppData/Localフォルダ。1人のユーザがこのPCだけで利用できるファイルを入れる
   398:   public static String sgsHomeDirectory;  //ホームディレクトリ
   399:   public static String sgsCurrentDirectory;  //カレントディレクトリ
   400: 
   401:   public static File sgsIniParentDirectory;  //Windowsのみ。設定ファイルの親ディレクトリ。なければnull。設定ファイルを-iniで指定したときもnull
   402:   public static String sgsIniParentPath;  //Windowsのみ。設定ファイルの親ディレクトリのパス。なければnull
   403:   public static File sgsIniFile;  //設定ファイル
   404:   public static String sgsIniPath;  //設定ファイルのパス
   405: 
   406:   public static boolean sgsSaveOnExit;  //true=終了時に設定を保存する
   407:   public static JCheckBoxMenuItem sgsSaveOnExitCheckBox;
   408:   public static String sgsSaveiconValue;
   409:   public static String sgsIrbbenchValue;
   410: 
   411:   public static HashMap<String,String> sgsDefaultMap;  //デフォルトの設定。SGS_DEFAULT_PARAMETERSを変換したもの
   412:   public static HashMap<String,String> sgsStartMap;  //開始時の設定。デフォルトの設定に言語などを加えたもの。これと異なる値を持つキーだけ保存する
   413:   public static HashMap<String,String> sgsCurrentMap;  //現在の設定
   414:   public static HashMap<String,HashMap<String,String>> sgsRootMap;  //保存されているすべての設定。タイトル→設定
   415: 
   416:   public static JMenu sgsMenu;  //設定メニュー
   417: 
   418:   //DictionaryComparator
   419:   //  辞書順コンパレータ
   420:   //  大文字と小文字を区別しない
   421:   //  数字の並びを数の大小で比較する
   422:   //  一致したときは改めて大文字と小文字を区別して数字を特別扱いしないで比較し直す
   423:   public static final Comparator<String> DictionaryComparator = new Comparator<String> () {
   424:     @Override public int compare (String s1, String s2) {
   425:       int l1 = s1.length ();
   426:       int l2 = s2.length ();
   427:       int b1, b2;  //部分文字列の開始位置(このインデックスを含む)
   428:       int e1, e2;  //部分文字列の終了位置(このインデックスを含まない)
   429:       int f = 0;  //比較結果
   430:     compare:
   431:       {
   432:         for (b1 = 0, b2 = 0; b1 < l1 && b2 < l2; b1 = e1, b2 = e2) {
   433:           int c1, c2;
   434:           //数字と数字以外の境目を探して部分文字列の終了位置にする
   435:           e1 = b1;
   436:           c1 = s1.charAt (e1);
   437:           c1 = ('0' - 1) - c1 & c1 - ('9' + 1);  //(c1<0)==isdigit(c1)
   438:           for (e1++; e1 < l1; e1++) {
   439:             c2 = s1.charAt (e1);
   440:             c2 = ('0' - 1) - c2 & c2 - ('9' + 1);  //(c2<0)==isdigit(c2)
   441:             if ((c1 ^ c2) < 0) {  //数字と数字以外の境目
   442:               break;
   443:             }
   444:             c1 = c2;
   445:           }
   446:           e2 = b2;
   447:           c1 = s2.charAt (e2);
   448:           c1 = ('0' - 1) - c1 & c1 - ('9' + 1);  //(c1<0)==isdigit(c1)
   449:           for (e2++; e2 < l2; e2++) {
   450:             c2 = s2.charAt (e2);
   451:             c2 = ('0' - 1) - c2 & c2 - ('9' + 1);  //(c2<0)==isdigit(c2)
   452:             if ((c1 ^ c2) < 0) {  //数字と数字以外の境目
   453:               break;
   454:             }
   455:             c1 = c2;
   456:           }
   457:           c1 = s1.charAt (b1);
   458:           c2 = s2.charAt (b2);
   459:           if ((('0' - 1) - c1 & c1 - ('9' + 1) & ('0' - 1) - c2 & c2 - ('9' + 1)) < 0) {  //両方数字のとき
   460:             //ゼロサプレスする
   461:             for (; b1 < e1 && s1.charAt (b1) == '0'; b1++) {
   462:             }
   463:             for (; b2 < e2 && s2.charAt (b2) == '0'; b2++) {
   464:             }
   465:             //桁数を比較する
   466:             f = (e1 - b1) - (e2 - b2);
   467:             if (f != 0) {
   468:               break compare;
   469:             }
   470:             //数字を比較する
   471:             for (; b1 < e1 && b2 < e2; b1++, b2++) {
   472:               f = s1.charAt (b1) - s2.charAt (b2);
   473:               if (f != 0) {
   474:                 break compare;
   475:               }
   476:             }
   477:           } else {  //どちらかが数字ではないとき
   478:             //大文字と小文字を区別しないで比較する
   479:             //  小文字化してから比較する
   480:             for (; b1 < e1 && b2 < e2; b1++, b2++) {
   481:               c1 = s1.charAt (b1);
   482:               c2 = s2.charAt (b2);
   483:               f = ((c1 + ((('A' - 1) - c1 & c1 - ('Z' + 1)) >> 31 & 'a' - 'A')) -
   484:                    (c2 + ((('A' - 1) - c2 & c2 - ('Z' + 1)) >> 31 & 'a' - 'A')));
   485:               if (f != 0) {
   486:                 break compare;
   487:               }
   488:             }
   489:             if (b1 < e1 || b2 < e2) {  //部分文字列が片方だけ残っているとき
   490:               //  一致したまま片方だけ残るのは両方数字以外のときだけ
   491:               //  部分文字列が先に終わった方は文字列が終わっているか数字が続いている
   492:               //  部分文字列が残っている方は数字ではないので1文字比較するだけで大小関係がはっきりする
   493:               //f = (b1 < l1 ? s1.charAt (b1) : -1) - (b2 < l2 ? s2.charAt (b2) : -1);
   494:               f = (e1 - b1) - (e2 - b2);  //部分文字列が片方だけ残っているときは残っている方が大きい
   495:               break compare;
   496:             }
   497:           }  //if 両方数字のとき/どちらかが数字ではないとき
   498:         }  //for b1,b2
   499:         f = (l1 - b1) - (l2 - b2);  //文字列が片方だけ残っているときは残っている方が大きい
   500:         //一致したときは改めて大文字と小文字を区別して数字を特別扱いしないで比較し直す
   501:         if (f == 0) {
   502:           for (b1 = 0, b2 = 0; b1 < l1 && b2 < l2; b1++, b2++) {
   503:             f = s1.charAt (b1) - s2.charAt (b2);
   504:             if (f != 0) {
   505:               break compare;
   506:             }
   507:           }
   508:         }
   509:       }  //compare
   510:       return (f >> 31) - (-f >> 31);
   511:     }  //compare(String,String)
   512:   };  //DictionaryComparator
   513: 
   514:   //sgsInit ()
   515:   //  設定の初期化
   516:   public static void sgsInit () {
   517: 
   518:     sgsAppDataRoamingFolder = null;
   519:     sgsAppDataLocalFolder = null;
   520:     sgsHomeDirectory = null;
   521:     sgsCurrentDirectory = null;
   522: 
   523:     sgsIniParentDirectory = null;
   524:     sgsIniParentPath = null;
   525:     sgsIniFile = null;
   526:     sgsIniPath = null;
   527: 
   528:     sgsSaveOnExit = true;  //終了時に設定を保存する
   529:     sgsSaveOnExitCheckBox = null;
   530: 
   531:     sgsSaveiconValue = null;
   532:     sgsIrbbenchValue = null;
   533: 
   534:     //デフォルトの設定
   535:     //  SGS_DEFAULT_PARAMETERSを分解してデフォルトの設定sgsDefaultMapを作る
   536:     //  デフォルトの設定sgsDefaultMapには設定名を表すキー"_"が存在しない
   537:     sgsDefaultMap = new HashMap<String,String> ();
   538:     {
   539:       String[] a = SGS_DEFAULT_PARAMETERS.split (";");
   540:       for (int i = 0, l = a.length; i < l; i += 2) {
   541:         String key = a[i];
   542:         String value = i + 1 < l ? a[i + 1] : "";  //splitで末尾の空要素が削除されるのでa[i+1]が存在しないとき""とみなす
   543:         sgsDefaultMap.put (key, value);
   544:       }
   545:     }
   546:     //  ユニット
   547:     //  SCSI HDのイメージファイル
   548:     //    拡張  内蔵  sc[0-7]  sc[8-15]
   549:     //    -----------------------------
   550:     //    有効  有効    拡張     内蔵
   551:     //    有効  無効    拡張     無効
   552:     //    無効  有効    内蔵     無効
   553:     //    無効  無効    無効     無効
   554:     for (int i = 0; i < FDC.FDC_MAX_UNITS; i++) {
   555:       sgsDefaultMap.put ("fd" + i, "none");  //FD
   556:     }
   557:     for (int i = 0; i < 16; i++) {
   558:       sgsDefaultMap.put ("hd" + i, "none");  //SASIまたはSCSI
   559:       sgsDefaultMap.put ("sa" + i, "none");  //SASI
   560:       sgsDefaultMap.put ("sc" + i, "none");  //SCSI
   561:     }
   562:     for (int i = 0; i < HFS.HFS_MAX_UNITS; i++) {
   563:       sgsDefaultMap.put ("hf" + i, "none");  //HFS
   564:     }
   565:     //  ヒストリ
   566:     for (int i = 0; i < JFileChooser2.MAXIMUM_HISTORY_COUNT; i++) {
   567:       sgsDefaultMap.put ("fdhistory" + i, "none");
   568:       sgsDefaultMap.put ("sahistory" + i, "none");
   569:       sgsDefaultMap.put ("schistory" + i, "none");
   570:       sgsDefaultMap.put ("hfhistory" + i, "none");
   571:     }
   572:     //  ウインドウの位置とサイズと状態
   573:     for (String key : SGS_FRAME_KEYS) {
   574:       sgsDefaultMap.put (key + "rect", "0,0,0,0");  //ウインドウの位置とサイズ(x,y,width,height)
   575:       sgsDefaultMap.put (key + "stat", "normal");  //ウインドウの状態(iconified/maximized/h-maximized/v-maximized/normal)
   576:       sgsDefaultMap.put (key + "open", "off");  //ウインドウが開いているかどうか。メインのフレームも終了時にはoffになっている
   577:     }
   578: 
   579:     //開始時の設定
   580:     //  デフォルトの設定sgsDefaultMapのコピーに言語やホームディレクトリを追加して開始時の設定sgsStartMapを作る
   581:     //  開始時の設定sgsStartMapには設定名を表すキー"_"が存在しない
   582:     sgsStartMap = new HashMap<String,String> (sgsDefaultMap);
   583: 
   584:     //hf0の初期値はカレントディレクトリ
   585:     sgsStartMap.put ("hf0", sgsHomeDirectory != null ? sgsHomeDirectory : HFS.HFS_DUMMY_UNIT_NAME);
   586: 
   587:     //言語
   588:     sgsStartMap.put ("lang", Multilingual.mlnLang);
   589: 
   590:     if (false) {
   591:       //すべての環境変数を表示する
   592:       System.out.println ("\n[System.getenv()]");
   593:       new TreeMap<String,String> (System.getenv ()).forEach ((k, v) -> System.out.println (k + " = " + v));  //System.getenv()はMap<String,String>
   594:     }
   595:     if (false) {
   596:       //すべてのプロパティを表示する
   597:       System.out.println ("\n[System.getProperties()]");
   598:       TreeMap<String,String> m = new TreeMap<String,String> ();
   599:       System.getProperties ().forEach ((k, v) -> m.put (k.toString (), v.toString ()));  //System.getProperties()はHashtable<Object,Object>
   600:       m.forEach ((k, v) -> System.out.println (k + " = " + v));
   601:     }
   602: 
   603:     //AppDataフォルダ
   604:     boolean isWindows = System.getProperty ("os.name").indexOf ("Windows") >= 0;  //true=Windows
   605:     sgsAppDataRoamingFolder = isWindows ? System.getenv ("APPDATA") : null;
   606:     sgsAppDataLocalFolder = isWindows ? System.getenv ("LOCALAPPDATA") : null;
   607:     //ホームディレクトリ
   608:     //  new File("")
   609:     sgsHomeDirectory = System.getProperty ("user.home");
   610:     //カレントディレクトリ
   611:     //  new File(".")
   612:     sgsCurrentDirectory = System.getProperty ("user.dir");
   613: 
   614:     //デフォルトの設定ファイルの場所
   615:     if (sgsAppDataRoamingFolder != null) {  //Windows
   616:       sgsIniParentPath = new File (sgsAppDataRoamingFolder + File.separator + SGS_APPDATA_FOLDER).getAbsolutePath ();
   617:       sgsIniParentDirectory = new File (sgsIniParentPath);
   618:       sgsIniPath = sgsIniParentPath + File.separator + SGS_INI;
   619:       sgsIniFile = new File (sgsIniPath);
   620:     } else {  //Windows以外
   621:       sgsIniParentPath = null;
   622:       sgsIniParentDirectory = null;
   623:       sgsIniPath = new File ((sgsHomeDirectory != null ? sgsHomeDirectory :
   624:                               sgsCurrentDirectory != null ? sgsCurrentDirectory :
   625:                               ".") + File.separator + SGS_INI).getAbsolutePath ();
   626:       sgsIniFile = new File (sgsIniPath);
   627:     }
   628: 
   629:     //現在の設定
   630:     //  開始時の設定sgsStartMapをコピーして現在の設定sgsCurrentMapを作る
   631:     //  ここで初めて設定名を表すキー"_"を追加する
   632:     sgsCurrentMap = new HashMap<String,String> (sgsStartMap);
   633:     sgsCurrentMap.put ("_", "");
   634: 
   635:     //保存されているすべての設定のマップ
   636:     sgsRootMap = new HashMap<String,HashMap<String,String>> ();
   637:     sgsRootMap.put ("", sgsCurrentMap);
   638: 
   639:     //コマンドラインのパラメータを読み取る
   640:     //  -iniで設定ファイルが変更される場合がある
   641:     HashMap<String,String> argumentMap = new HashMap<String,String> ();
   642:     int fdNumber = 0;
   643:     int hdNumber = 0;
   644:     int scNumber = 0;
   645:     int hfNumber = 0;
   646:     for (int i = 0; i < XEiJ.prgArgs.length; i++) {
   647:       String key = null;  //キー
   648:       String value = XEiJ.prgArgs[i];  //引数。nullではないはず
   649:     arg:
   650:       {
   651:         boolean boot = false;  //true=valueは-bootの値
   652:         if (value.startsWith ("-")) {  //引数が"-"で始まっている
   653:           //!!! 値が必要なものと必要でないものを区別したい
   654:           int k = value.indexOf ('=', 1);
   655:           if (k >= 0) {  //引数が"-"で始まっていて2文字目以降に"="がある
   656:             key = value.substring (1, k);  //"-"の後ろから"="の手前まではキー
   657:             value = value.substring (k + 1);  //"="の後ろは値
   658:           } else {  //引数が"-"で始まっていて2文字目以降に"="がない
   659:             //!!! "-"で始まる引数はすべてキーとみなされるので"-キー 値"の形では値に負の数値を書くことはできない
   660:             key = value.substring (1);  //"-"の後ろはキー
   661:             value = (i + 1 < XEiJ.prgArgs.length && !XEiJ.prgArgs[i + 1].startsWith ("-") ?  //次の引数があって次の引数が"-"で始まっていない
   662:                      XEiJ.prgArgs[++i]  //次の引数は値
   663:                      :  //次の引数がないまたは次の引数が"-"で始まっている
   664:                      "1");  //値は"1"
   665:           }
   666:           if (!key.equalsIgnoreCase ("boot")) {  //-bootではない
   667:             break arg;
   668:           }
   669:           boot = true;
   670:         }
   671:         //引数が"-"で始まっていないまたは-bootの値
   672:         if (SGS_BOOT_DEVICE_PATTERN.matcher (value).matches ()) {  //起動デバイス名のとき
   673:           //ファイルやディレクトリを探さず起動デバイスだけ設定する
   674:           key = "boot";
   675:           break arg;
   676:         }
   677:         String valueWithoutColonR = value.endsWith (":R") ? value.substring (0, value.length () - 2) : value;  //末尾の":R"を取り除いた部分
   678:         File file = new File (valueWithoutColonR);
   679:         if (file.isDirectory ()) {  //ディレクトリがある
   680:           key = "hf" + hfNumber++;  //HFS
   681:         } else if (file.isFile ()) {  //ファイルがある
   682:           //FDMedia.fdmPathToMediaが大きすぎるファイルを処理できないので、
   683:           //先に拡張子でハードディスクを区別する
   684:           if (valueWithoutColonR.toUpperCase ().endsWith (".HDF")) {
   685:             key = "sa" + hdNumber++;  //SASI ハードディスク
   686:           } else if (valueWithoutColonR.toUpperCase ().endsWith (".HDS")) {
   687:             key = "sc" + scNumber++;  //SCSI ハードディスク/CD-ROM
   688:           } else if (FDMedia.fdmPathToMedia (valueWithoutColonR, null) != null) {
   689:             key = "fd" + fdNumber++;  //フロッピーディスク
   690:           } else if (HDMedia.hdmPathToMedia (valueWithoutColonR, null) != null) {
   691:             key = "sa" + hdNumber++;  //SASI ハードディスク
   692:           } else {
   693:             key = "sc" + scNumber++;  //SCSI ハードディスク/CD-ROM
   694:           }
   695:         } else {  //ファイルもディレクトリもない
   696:           String[] zipSplittedName = XEiJ.RSC_ZIP_SEPARATOR.split (valueWithoutColonR, 2);  //*.zip/entryを*.zipとentryに分ける
   697:           if (zipSplittedName.length == 2 &&  //*.zip/entryで
   698:               new File (zipSplittedName[0]).isFile ()) {  //*.zipがある
   699:             if (FDMedia.fdmPathToMedia (valueWithoutColonR, null) != null) {
   700:               key = "fd" + fdNumber++;  //フロッピーディスク
   701:             } else if (HDMedia.hdmPathToMedia (valueWithoutColonR, null) != null) {
   702:               key = "sa" + hdNumber++;  //SASI ハードディスク
   703:             } else {
   704:               System.out.println (Multilingual.mlnJapanese ? value + " は不明な起動デバイスです" :
   705:                                   value + " is unknown boot device");
   706:               continue;
   707:             }
   708:           } else {  //*.zip.entryでないか*.zipがない
   709:             System.out.println (Multilingual.mlnJapanese ? value + " は不明な起動デバイスです" :
   710:                                 value + " is unknown boot device");
   711:             continue;
   712:           }
   713:         }
   714:         if (boot) {  //-bootの値のとき
   715:           sgsPutParameter (argumentMap, "boot", key);  //起動デバイスを設定する
   716:         }
   717:       }  //arg
   718:       //その他のオプション
   719:       switch (key) {
   720:       case "ini":  //設定ファイル
   721:         sgsIniParentPath = null;
   722:         sgsIniParentDirectory = null;
   723:         sgsIniPath = new File (value).getAbsolutePath ();
   724:         sgsIniFile = new File (sgsIniPath);
   725:         break;
   726:       case "saveicon":
   727:         sgsSaveiconValue = value;
   728:         break;
   729:       case "irbbench":
   730:         sgsIrbbenchValue = value;
   731:         break;
   732:       default:
   733:         sgsPutParameter (argumentMap, key, value);  //パラメータを設定する
   734:       }
   735:     }
   736:     System.out.println (Multilingual.mlnJapanese ? "設定ファイルは " + sgsIniPath + " です" :
   737:                         "INI file is " + sgsIniPath);
   738: 
   739:     //設定ファイルを読み込んですべての設定sgsRootMapに格納する
   740:     sgsDecodeRootMap (sgsLoadIniFile ());
   741: 
   742:     //コマンドラインなどのパラメータで使用する設定を選択する
   743:     if (argumentMap.containsKey ("config")) {  //キー"config"が指定されているとき
   744:       String name = argumentMap.get ("config");  //使用する設定名
   745:       if (name.equals ("default")) {  //デフォルトの設定
   746:         sgsCurrentMap.clear ();  //古いマップを消しておく
   747:         sgsCurrentMap = new HashMap<String,String> (sgsStartMap);  //開始時の設定を現在の設定にコピーする
   748:         sgsCurrentMap.put ("_", "");  //設定名を加える
   749:         sgsRootMap.put ("", sgsCurrentMap);  //新しいマップを繋ぎ直す
   750:       } else if (name.length () != 0 &&  //使用する設定名が""以外で
   751:                  sgsRootMap.containsKey (name)) {  //存在するとき
   752:         sgsCurrentMap.clear ();  //古いマップを消しておく
   753:         sgsCurrentMap = new HashMap<String,String> (sgsRootMap.get (name));  //指定された設定を現在の設定にコピーする
   754:         sgsCurrentMap.put ("_", "");  //設定名を元に戻す
   755:         sgsRootMap.put ("", sgsCurrentMap);  //新しいマップを繋ぎ直す
   756:       }
   757:       argumentMap.remove ("config");  //キー"config"は指定されなかったことにする
   758:     }
   759: 
   760:     //コマンドラインなどのパラメータを現在の設定に上書きする
   761:     //argumentMap.forEach ((k, v) -> sgsCurrentMap.put (k, v));
   762:     for (String key : argumentMap.keySet ()) {
   763:       sgsCurrentMap.put (key, argumentMap.get (key));
   764:     }
   765: 
   766:     //PRG
   767:     String paramLang = sgsCurrentMap.get ("lang").toLowerCase ();
   768:     Multilingual.mlnChange (paramLang.equals ("ja") ? "ja" : "en");
   769:     XEiJ.prgVerbose = sgsGetOnOff ("verbose");  //冗長表示
   770:     //SGS
   771:     sgsSaveOnExit = sgsGetOnOff ("saveonexit");  //終了時に設定を保存するか
   772:     //LNF
   773:     //  色
   774:     //KBD
   775:     //PNL
   776:     //MUS
   777:     //MPU
   778:     //FPK
   779:     //BUS
   780:     //MMR
   781:     //CRT
   782:     if (CRTC.CRT_ENABLE_INTERMITTENT) {
   783:       CRTC.crtIntermittentInterval = XEiJ.fmtParseInt (sgsCurrentMap.get ("intermittent"), 0, 0, 4, 0);  //間欠描画
   784:     }
   785:     if (CRTC.CRT_EXTENDED_GRAPHIC) {
   786:       CRTC.crtExtendedGraphicRequest = sgsGetOnOff ("extendedgraphic");  //拡張グラフィック画面
   787:     }
   788:     //SND
   789:     SoundSource.sndPlayOn = sgsGetOnOff ("sound");  //音声出力
   790:     SoundSource.sndVolume = XEiJ.fmtParseInt (sgsCurrentMap.get ("volume"), 0, 0, SoundSource.SND_VOLUME_MAX, SoundSource.SND_VOLUME_DEFAULT);  //ボリューム
   791:     {
   792:       String s = sgsCurrentMap.get ("soundinterpolation").toLowerCase ();
   793:       SoundSource.sndRateConverter = (s.equals ("thinning") ? SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.THINNING_MONO : SoundSource.SNDRateConverter.THINNING_STEREO :  //間引き
   794:                                       s.equals ("linear") ? SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.LINEAR_MONO : SoundSource.SNDRateConverter.LINEAR_STEREO :  //線形補間
   795:                                       s.equals ("constant-area") ? SoundSource.SNDRateConverter.CONSTANT_AREA_STEREO_48000 :  //区分定数面積補間
   796:                                       s.equals ("linear-area") ? SoundSource.SNDRateConverter.LINEAR_AREA_STEREO_48000 :  //線形面積補間
   797:                                       SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.LINEAR_MONO : SoundSource.SNDRateConverter.LINEAR_STEREO);  //線形補間
   798:     }
   799:     //OPM
   800:     OPM.opmOutputMask = sgsGetOnOff ("opmoutput") ? -1 : 0;  //OPM出力
   801:     //PCM
   802:     {
   803:       ADPCM.pcmOutputOn = sgsGetOnOff ("pcmoutput");  //PCM出力
   804:       String s = sgsCurrentMap.get ("pcminterpolation").toLowerCase ();
   805:       ADPCM.pcmInterpolationAlgorithm = (s.equals ("constant") ? ADPCM.PCM_INTERPOLATION_CONSTANT :  //区分定数補間
   806:                                          s.equals ("linear") ? ADPCM.PCM_INTERPOLATION_LINEAR :  //線形補間
   807:                                          s.equals ("hermite") ? ADPCM.PCM_INTERPOLATION_HERMITE :  //エルミート補間
   808:                                          ADPCM.PCM_INTERPOLATION_LINEAR);  //線形補間
   809:       ADPCM.pcmOSCFreqRequest = XEiJ.fmtParseInt (sgsCurrentMap.get ("pcmoscfreq"), 0, 0, 1, 0);  //原発振周波数
   810:     }
   811:     //FDC
   812:     //fdNはFDCで解釈する
   813:     //HDC
   814:     //hdNはHDCで解釈する
   815:     //SPC
   816:     //scNはSPCで解釈する
   817:     //HFS
   818:     //hfNはHFSで解釈する
   819:     //PPI
   820:     //SMR
   821:     //BNK
   822:     //FNT
   823:     //PRN
   824: 
   825:     //ウインドウの位置とサイズと状態
   826:     for (String key : SGS_FRAME_KEYS) {
   827:       //ウインドウの位置とサイズ
   828:       String[] a = sgsCurrentMap.get (key + "rect").split (",");
   829:       if (a.length == 4) {
   830:         RestorableFrame.rfmSetBounds (key,
   831:                                       new Rectangle (XEiJ.fmtParseInt (a[0], 0, -4096, 4096, 0),
   832:                                                      XEiJ.fmtParseInt (a[1], 0, -4096, 4096, 0),
   833:                                                      XEiJ.fmtParseInt (a[2], 0, 64, 4096, 0),
   834:                                                      XEiJ.fmtParseInt (a[3], 0, 64, 4096, 0)));
   835:       }
   836:       //ウインドウの状態
   837:       String s = sgsCurrentMap.get (key + "stat").toLowerCase ();
   838:       RestorableFrame.rfmSetState (key,
   839:                                    s.equals ("iconified") ? Frame.ICONIFIED :  //アイコン化する
   840:                                    s.equals ("maximized") ? Frame.MAXIMIZED_BOTH :  //最大化する
   841:                                    s.equals ("h-maximized") ? Frame.MAXIMIZED_HORIZ :  //水平方向だけ最大化する
   842:                                    s.equals ("v-maximized") ? Frame.MAXIMIZED_VERT :  //垂直方向だけ最大化する
   843:                                    Frame.NORMAL);  //通常表示
   844:       //ウインドウが開いているかどうか
   845:       RestorableFrame.rfmSetOpened (key, sgsGetOnOff (key + "open"));
   846:     }
   847: 
   848:     if (sgsIrbbenchValue != null) {
   849:       InstructionBenchmark.irbBench (sgsIrbbenchValue);
   850:       System.exit (0);
   851:     }
   852: 
   853:   }  //sgsInit()
   854: 
   855:   //sgsTini ()
   856:   //  後始末
   857:   public static void sgsTini () {
   858:     if (sgsSaveOnExit) {  //終了時に設定を保存する
   859:       sgsSaveAllSettings ();
   860:     }
   861:   }  //sgsTini()
   862: 
   863: 
   864: 
   865:   //value = sgsGetString (key)
   866:   //  現在の設定を読み出す。前後の空白を取り除く。noneを""とみなす
   867:   public static String sgsGetString (String key) {
   868:     String value = sgsCurrentMap.get (key);
   869:     if (value == null) {
   870:       System.err.println ("sgsGetString: undefined key " + key);
   871:       return "";
   872:     }
   873:     value = value.trim ();  //前後の空白を取り除く
   874:     return value.equalsIgnoreCase ("none") ? "" : value;  //noneを""とみなす
   875:   }
   876: 
   877:   //sgsPutString (key, value)
   878:   //  現在の設定に書き込む。前後の空白を取り除く。""をnoneとみなす
   879:   public static void sgsPutString (String key, String value) {
   880:     if (!sgsCurrentMap.containsKey (key)) {
   881:       System.err.println ("sgsPutString: undefined key " + key);
   882:       return;
   883:     }
   884:     value = value.trim ();  //前後の空白を取り除く
   885:     sgsCurrentMap.put (key, value.length () == 0 ? "none" : value);  //""をnoneとみなす
   886:   }
   887: 
   888:   //b = sgsGetOnOff (key)
   889:   //  現在の設定を読み出す。前後の空白を取り除く。1とonとyesをtrue、それ以外をfalseとみなす
   890:   public static boolean sgsGetOnOff (String key) {
   891:     String value = sgsCurrentMap.get (key);
   892:     if (value == null) {
   893:       System.err.println ("sgsGetOnOff: undefined key " + key);
   894:       return false;
   895:     }
   896:     value = value.trim ();  //前後の空白を取り除く
   897:     return value.equals ("1") || value.equalsIgnoreCase ("on") || value.equalsIgnoreCase ("yes");  //1とonとyesをtrue、それ以外をfalseとみなす
   898:   }
   899: 
   900:   //sgsPutOnOff (key, b)
   901:   //  現在の設定に書き込む。trueをon、falseをoffとみなす
   902:   public static void sgsPutOnOff (String key, boolean b) {
   903:     if (!sgsCurrentMap.containsKey (key)) {
   904:       System.err.println ("sgsPutOnOff: undefined key " + key);
   905:       return;
   906:     }
   907:     sgsCurrentMap.put (key, b ? "on" : "off");  //trueをon、falseをoffとみなす
   908:   }
   909: 
   910:   //i = sgsGetInt (key)
   911:   //i = sgsGetInt (key, i0)
   912:   //  現在の設定から整数を読み出す。""のときi0になる
   913:   public static int sgsGetInt (String key) {
   914:     return sgsGetInt (key, 0);
   915:   }
   916:   public static int sgsGetInt (String key, int i0) {
   917:     String value = sgsCurrentMap.get (key);
   918:     if (value == null) {
   919:       System.err.println ("sgsGetInt: undefined key " + key);
   920:       return i0;
   921:     }
   922:     value = value.trim ();  //前後の空白を取り除く
   923:     if (value.length () != 0) {
   924:       try {
   925:         return Integer.parseInt (value, 10);
   926:       } catch (NumberFormatException nfe) {
   927:       }
   928:     }
   929:     return i0;
   930:   }
   931: 
   932:   //sgsPutInt (key, i)
   933:   //sgsPutInt (key, i, i0)
   934:   //  現在の設定に整数を書き込む。i0のとき""になる
   935:   public static void sgsPutInt (String key, int i) {
   936:     sgsPutInt (key, i, 0);
   937:   }
   938:   public static void sgsPutInt (String key, int i, int i0) {
   939:     if (!sgsCurrentMap.containsKey (key)) {
   940:       System.err.println ("sgsPutInt: undefined key " + key);
   941:       return;
   942:     }
   943:     sgsCurrentMap.put (key, i == i0 ? "" : String.valueOf (i));
   944:   }
   945: 
   946:   //ia = sgsGetIntArray (key)
   947:   //ia = sgsGetIntArray (key, n)
   948:   //  現在の設定を読み出す。','で区切る。前後の空白を取り除く。""を0に、それ以外の文字列を10進数とみなして整数に変換する。失敗したときは0
   949:   //  nは要素の数。-1=可変
   950:   public static int[] sgsGetIntArray (String key) {
   951:     return sgsGetIntArray (key, -1);
   952:   }
   953:   public static int[] sgsGetIntArray (String key, int n) {
   954:     String value = sgsCurrentMap.get (key);
   955:     if (value == null) {
   956:       System.err.println ("sgsGetIntArray: undefined key " + key);
   957:       value = "";
   958:     }
   959:     String[] sa = value.length () == 0 ? new String[0] : value.split (",");  //','で区切る。"".split(",").length==1であることに注意
   960:     if (n < 0) {  //可変
   961:       n = sa.length;  //要素の数
   962:     }
   963:     int[] ia = new int[n];
   964:     Arrays.fill (ia, 0);
   965:     for (int i = 0; i < n && i < sa.length; i++) {
   966:       String s = sa[i].trim ();  //前後の空白を取り除く
   967:       if (s.length () != 0) {
   968:         try {
   969:           ia[i] = Integer.parseInt (s, 10);  //10進数とみなして整数に変換する
   970:         } catch (NumberFormatException nfe) {
   971:         }
   972:       }
   973:     }
   974:     return ia;
   975:   }
   976: 
   977:   //sgsPutIntArray (key, ia)
   978:   //  現在の設定に書き込む。0を""に、それ以外の整数を10進数の文字列に変換する。','で区切って並べる。末尾の0の並びを省略する
   979:   public static void sgsPutIntArray (String key, int[] ia) {
   980:     if (!sgsCurrentMap.containsKey (key)) {
   981:       System.err.println ("sgsPutIntArray: undefined key " + key);
   982:       return;
   983:     }
   984:     int n = ia.length;
   985:     while (0 < n && ia[n - 1] == 0) {
   986:       n--;  //末尾の0の並びを省略する
   987:     }
   988:     StringBuilder sb = new StringBuilder ();
   989:     for (int i = 0; i < n; i++) {
   990:       if (i != 0) {
   991:         sb.append (',');  //','で区切って並べる
   992:       }
   993:       if (ia[i] != 0) {  //0を""に、それ以外の整数を10進数の文字列に変換する
   994:         sb.append (ia[i]);
   995:       }
   996:     }
   997:     sgsCurrentMap.put (key, sb.toString ());
   998:   }
   999: 
  1000:   //array = sgsGetData (key)
  1001:   //  現在の設定を読み出す。gzip+base64で解凍する
  1002:   //  ""のときは長さが0の配列を返す
  1003:   public static byte[] sgsGetData (String key) {
  1004:     String value = sgsCurrentMap.get (key);
  1005:     if (value == null) {
  1006:       System.err.println ("sgsGetData: undefined key " + key);
  1007:       value = "";
  1008:     }
  1009:     return value.length () == 0 ? new byte[0] : ByteArray.byaDecodeGzip (ByteArray.byaDecodeBase64 (value));
  1010:   }
  1011: 
  1012:   //sgsPutData (key, array)
  1013:   //sgsPutData (key, array, offset, length)
  1014:   //  現在の設定に書き込む。gzip+base64で圧縮する
  1015:   //  中途半端に短くすると長さで種類を見分けることができなくなるので末尾の0は切り捨てない
  1016:   //  すべて0のときは""を書き込む
  1017:   public static void sgsPutData (String key, byte[] array) {
  1018:     sgsPutData (key, array, 0, array.length);
  1019:   }
  1020:   public static void sgsPutData (String key, byte[] array, int offset, int length) {
  1021:     if (!sgsCurrentMap.containsKey (key)) {
  1022:       System.err.println ("sgsPutData: undefined key " + key);
  1023:       return;
  1024:     }
  1025:     String value = "";
  1026:     for (int i = 0; i < length; i++) {
  1027:       if (array[offset + i] != 0) {  //0ではない
  1028:         value = ByteArray.byaEncodeBase64 (ByteArray.byaEncodeGzip (array, offset, length));
  1029:         break;
  1030:       }
  1031:     }
  1032:     sgsCurrentMap.put (key, value);
  1033:   }
  1034: 
  1035: 
  1036: 
  1037:   //sgsMakeMenu ()
  1038:   //  「設定」メニューを作る
  1039:   public static void sgsMakeMenu () {
  1040:     //アクションリスナー
  1041:     ActionListener listener = new ActionListener () {
  1042:       @Override public void actionPerformed (ActionEvent ae) {
  1043:         Object source = ae.getSource ();
  1044:         String command = ae.getActionCommand ();
  1045:         switch (command) {
  1046:         case "Save settings on exit":  //終了時に設定を保存する
  1047:           sgsSaveOnExit = ((JCheckBoxMenuItem) ae.getSource ()).isSelected ();  //終了時に設定を保存するか
  1048:           break;
  1049:         case "Delete all settings":  //すべての設定を消去する
  1050:           sgsDeleteAllSettings ();
  1051:           break;
  1052:         }
  1053:       }
  1054:     };
  1055:     //メニュー
  1056:     sgsMenu = Multilingual.mlnText (
  1057:       ComponentFactory.createMenu (
  1058:         "Configuration file",
  1059:         sgsSaveOnExitCheckBox = Multilingual.mlnText (
  1060:           ComponentFactory.createCheckBoxMenuItem (sgsSaveOnExit, "Save settings on exit", listener), "ja", "終了時に設定を保存する"),
  1061:         ComponentFactory.createHorizontalSeparator (),
  1062:         Multilingual.mlnText (ComponentFactory.createMenuItem ("Delete all settings", listener), "ja", "すべての設定を消去する")),
  1063:       "ja", "設定ファイル");
  1064:   }  //sgsMakeMenu()
  1065: 
  1066:   //sgsSaveAllSettings ()
  1067:   //  設定ファイルを保存する
  1068:   public static void sgsSaveAllSettings () {
  1069:     //MLN
  1070:     sgsCurrentMap.put ("lang", Multilingual.mlnLang);  //言語
  1071:     //PRG
  1072:     sgsCurrentMap.put ("verbose", XEiJ.prgVerbose ? "on" : "off");  //冗長表示
  1073:     //SGS
  1074:     sgsCurrentMap.put ("saveonexit", sgsSaveOnExit ? "on" : "off");  //終了時に設定を保存する
  1075:     //LNF
  1076:     sgsCurrentMap.put ("hhssbb", LnF.lnfH0 + "," + LnF.lnfH1 + "," + LnF.lnfS0 + "," + LnF.lnfS1 + "," + LnF.lnfB0 + "," + LnF.lnfB1);  //色
  1077:     //PNL
  1078:     //MUS
  1079:     //FPK
  1080:     sgsCurrentMap.put ("fefunc", FEFunction.fpkOn ? "on" : "off");  //FEファンクション命令
  1081:     sgsCurrentMap.put ("rejectfloat", FEFunction.fpkRejectFloatOn ? "on" : "off");  //FLOATn.Xを組み込まない
  1082:     //BUS
  1083:     //MMR
  1084:     sgsCurrentMap.put ("memory", String.valueOf (MainMemory.mmrMemorySizeRequest >>> 20));  //メインメモリのサイズ
  1085:     sgsCurrentMap.put ("memorysave", MainMemory.mmrMemorySaveOn ? "on" : "off");  //メインメモリの内容を保存する
  1086:     sgsCurrentMap.put ("memorydata", MainMemory.mmrMemorySaveOn ? ByteArray.byaEncodeBase64 (ByteArray.byaEncodeGzip (MainMemory.mmrM8, 0x00000000, MainMemory.mmrMemorySizeCurrent)) : "");  //メインメモリの内容
  1087:     //CRT
  1088:     if (CRTC.CRT_ENABLE_INTERMITTENT) {
  1089:       sgsCurrentMap.put ("intermittent", String.valueOf (CRTC.crtIntermittentInterval));  //間欠描画
  1090:     }
  1091:     if (CRTC.CRT_EXTENDED_GRAPHIC) {
  1092:       sgsCurrentMap.put ("extendedgraphic", CRTC.crtExtendedGraphicRequest ? "on" : "off");  //拡張グラフィック画面
  1093:     }
  1094:     //SND
  1095:     sgsCurrentMap.put ("sound", SoundSource.sndPlayOn ? "on" : "off");  //音声出力
  1096:     sgsCurrentMap.put ("volume", String.valueOf (SoundSource.sndVolume));  //ボリューム
  1097:     sgsCurrentMap.put ("soundinterpolation",
  1098:                        SoundSource.sndRateConverter == (SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.THINNING_MONO : SoundSource.SNDRateConverter.THINNING_STEREO) ? "thinning" :  //間引き
  1099:                        SoundSource.sndRateConverter == (SoundSource.SND_CHANNELS == 1 ? SoundSource.SNDRateConverter.LINEAR_MONO : SoundSource.SNDRateConverter.LINEAR_STEREO) ? "linear" :  //線形補間
  1100:                        SoundSource.sndRateConverter == SoundSource.SNDRateConverter.CONSTANT_AREA_STEREO_48000 ? "constant-area" :  //区分定数面積補間
  1101:                        SoundSource.sndRateConverter == SoundSource.SNDRateConverter.LINEAR_AREA_STEREO_48000 ? "linear-area" :  //線形面積補間
  1102:                        "linear");  //線形補間
  1103:     //OPM
  1104:     sgsCurrentMap.put ("opmoutput", OPM.opmOutputMask != 0 ? "on" : "off");  //OPM出力
  1105:     //PCM
  1106:     sgsCurrentMap.put ("pcmoutput", ADPCM.pcmOutputOn ? "on" : "off");  //PCM出力
  1107:     sgsCurrentMap.put ("pcminterpolation",
  1108:                        ADPCM.pcmInterpolationAlgorithm == ADPCM.PCM_INTERPOLATION_CONSTANT ? "constant" :  //区分定数補間
  1109:                        ADPCM.pcmInterpolationAlgorithm == ADPCM.PCM_INTERPOLATION_LINEAR ? "linear" :  //線形補間
  1110:                        ADPCM.pcmInterpolationAlgorithm == ADPCM.PCM_INTERPOLATION_HERMITE ? "hermite" :  //エルミート補間
  1111:                        "linear");  //線形補間
  1112:     sgsCurrentMap.put ("pcmoscfreq", String.valueOf (ADPCM.pcmOSCFreqRequest));  //原発振周波数
  1113:     //PPI
  1114:     //SMR
  1115:     //BNK
  1116:     //FNT
  1117:     //PRN
  1118: 
  1119:     //ウインドウの位置とサイズと状態
  1120:     for (String key : SGS_FRAME_KEYS) {
  1121:       //ウインドウの位置とサイズ
  1122:       Rectangle bounds = RestorableFrame.rfmGetBounds (key);  //位置とサイズ
  1123:       sgsCurrentMap.put (key + "rect",
  1124:                          new StringBuilder ().
  1125:                          append (bounds.x).append (',').
  1126:                          append (bounds.y).append (',').
  1127:                          append (bounds.width).append (',').
  1128:                          append (bounds.height).toString ());
  1129:       //ウインドウの状態
  1130:       int state = RestorableFrame.rfmGetState (key);  //状態
  1131:       sgsCurrentMap.put (key + "stat",
  1132:                          (state & Frame.ICONIFIED) == Frame.ICONIFIED ? "iconified" :  //アイコン化されている
  1133:                          (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH ? "maximized" :  //最大化されている
  1134:                          (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_HORIZ ? "h-maximized" :  //水平方向だけ最大化されている
  1135:                          (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_VERT ? "v-maximized" :  //垂直方向だけ最大化されている
  1136:                          "normal");  //通常表示
  1137:       //ウインドウが開いているかどうか
  1138:       sgsCurrentMap.put (key + "open", RestorableFrame.rfmGetOpened (key) ? "on" : "off");
  1139:     }
  1140: 
  1141:     //保存する
  1142:     sgsSaveIniFile (sgsEncodeRootMap ());
  1143: 
  1144:   }  //sgsSaveSettings()
  1145: 
  1146:   //sgsDecodeRootMap (text)
  1147:   //  テキストをsgsRootMapに変換する
  1148:   public static void sgsDecodeRootMap (String text) {
  1149:     sgsRootMap.clear ();  //すべての設定を消す
  1150:     sgsCurrentMap.clear ();  //古いマップを消しておく
  1151:     sgsCurrentMap = new HashMap<String,String> (sgsStartMap);  //開始時の設定を現在の設定にコピーする
  1152:     sgsCurrentMap.put ("_", "");  //設定名を加える
  1153:     sgsRootMap.put ("", sgsCurrentMap);  //新しいマップを繋ぎ直す
  1154:     HashMap<String,String> map = sgsCurrentMap;  //現在変換中の設定は現在の設定
  1155:     for (String line : text.split ("\n")) {
  1156:       line = line.trim ();  //キーの前の空白と値の後の空白を取り除く
  1157:       if (line.length () == 0 ||  //空行
  1158:           line.startsWith ("#")) {  //注釈
  1159:         continue;
  1160:       }
  1161:       int i = line.indexOf ('=');
  1162:       if (i < 0) {  //'='がない
  1163:         continue;
  1164:       }
  1165:       String key = line.substring (0, i).trim ().toLowerCase ();  //キー。後('='の前)の空白を取り除いて小文字化する
  1166:       String value = line.substring (i + 1).trim ();  //値。前('='の後)の空白を取り除く
  1167:       if (key.equals ("_")) {  //設定名。新しい設定の最初の行
  1168:         if (sgsRootMap.containsKey (value)) {  //同じ設定名が2回出てきたとき
  1169:           if (false) {
  1170:             map = null;  //新しい設定名が指定されるまで読み飛ばす(最初に書いた設定が残る)
  1171:           } else {
  1172:             map = sgsRootMap.get (value);  //既存の設定に上書きする(最後に書いた設定が残る)
  1173:           }
  1174:         } else {  //新しい設定
  1175:           map = new HashMap<String,String> (sgsStartMap);  //開始時の設定をコピーする
  1176:           map.put (key, value);  //sgsPutParameterは設定名のキー"_"を受け付けないことに注意
  1177:           sgsRootMap.put (value, map);
  1178:         }
  1179:         continue;
  1180:       }
  1181:       if (map == null) {  //新しい設定名が指定されるまで読み飛ばす
  1182:         continue;
  1183:       }
  1184:       sgsPutParameter (map, key, value);
  1185:     }  //for line
  1186:   }  //sgsDecodeRootMap()
  1187: 
  1188:   //strings = sgsEncodeRootMap ()
  1189:   //  sgsRootMapを文字列のリストに変換する
  1190:   public static ArrayList<String> sgsEncodeRootMap () {
  1191:     ArrayList<String> strings = new ArrayList<String> ();  //StringBuilderは大きすぎると失敗する
  1192:     String[] nameArray = sgsRootMap.keySet ().toArray (new String[0]);  //設定名の配列
  1193:     Arrays.sort (nameArray, DictionaryComparator);  //設定名をソートする。設定名が""の現在の設定が先頭に来る
  1194:     for (String name : nameArray) {
  1195:       HashMap<String,String> map = sgsRootMap.get (name);  //個々の設定
  1196:       if (map != sgsCurrentMap) {  //(先頭の)現在の設定でないとき
  1197:         strings.add ("\n");  //1行空ける
  1198:       }
  1199:       String[] keyArray = map.keySet ().toArray (new String[0]);  //キーの配列
  1200:       Arrays.sort (keyArray, DictionaryComparator);  //キーをソートする。設定名以外のキーはすべて英小文字で始まるので設定名のキー"_"が先頭に来る
  1201:       for (String key : keyArray) {
  1202:         String value = map.get (key);
  1203:         if (!(map == sgsCurrentMap && key.equals ("_")) &&  //現在の設定の設定名でない
  1204:             !key.equals ("config") &&  //キー"config"は設定ファイルに出力しない
  1205:             !value.equals (sgsStartMap.get (key))) {  //開始時の設定にないか、開始時の設定と異なる
  1206:           strings.add (key);
  1207:           strings.add ("=");
  1208:           strings.add (value);  //これが極端に大きい場合がある
  1209:           strings.add ("\n");
  1210:         }
  1211:       }
  1212:     }
  1213:     return strings;
  1214:   }  //sgsEncodeRootMap()
  1215: 
  1216:   //sgsDeleteAllSettings ()
  1217:   //  すべての設定を削除する
  1218:   public static void sgsDeleteAllSettings () {
  1219:     if (JOptionPane.showConfirmDialog (
  1220:       XEiJ.frmFrame,
  1221:       Multilingual.mlnJapanese ? "すべての設定を消去しますか?" : "Do you want to delete all settings?",
  1222:       Multilingual.mlnJapanese ? "確認" : "Confirmation",
  1223:       JOptionPane.YES_NO_OPTION,
  1224:       JOptionPane.PLAIN_MESSAGE) == JOptionPane.YES_OPTION) {
  1225:       sgsDeleteIniFile ();  //設定ファイルを削除する
  1226:       sgsSaveOnExit = false;  //終了時に設定を保存しない
  1227:       sgsSaveOnExitCheckBox.setSelected (sgsSaveOnExit);
  1228:     }
  1229:   }  //sgsDeleteAllSettings()
  1230: 
  1231:   //sgsPutParameter (map, key, value)
  1232:   //  マップにパラメータを追加する
  1233:   //  デフォルトの設定sgsDefaultMapにないパラメータは無視される。設定名のキー"_"を受け付けないことに注意
  1234:   //  デフォルトの値が"off"または"on"のパラメータの値は"0","no","off"を指定すると"off"、それ以外は"on"に読み替えられる
  1235:   public static void sgsPutParameter (HashMap<String,String> map, String key, String value) {
  1236:     if (sgsDefaultMap.containsKey (key)) {  //設定できるパラメータ
  1237:       String defaultValue = sgsDefaultMap.get (key);  //デフォルトの値
  1238:       if (defaultValue.equals ("off") || defaultValue.equals ("on")) {  //デフォルトの値が"off"または"on"のとき
  1239:         value = (value.equals ("0") ||
  1240:                  value.equalsIgnoreCase ("no") ||
  1241:                  value.equalsIgnoreCase ("off") ? "off" : "on");  //"0","no","off"を"off"にそれ以外を"on"に読み替える
  1242:       }
  1243:       map.put (key, value);  //マップに追加する
  1244:     }
  1245:   }  //sgsPutParameter(HashMap<String,String>,String,String)
  1246: 
  1247: 
  1248: 
  1249:   //text = sgsLoadIniFile ()
  1250:   //  設定ファイルを読み込む
  1251:   public static String sgsLoadIniFile () {
  1252:     return XEiJ.rscGetTextFile (sgsIniPath);
  1253:   }  //sgsLoadIniFile()
  1254: 
  1255:   //sgsSaveIniFile ()
  1256:   //  設定ファイルに書き出す
  1257:   public static void sgsSaveIniFile (ArrayList<String> strings) {
  1258:     XEiJ.rscPutTextFile (sgsIniPath, strings);
  1259:   }
  1260: 
  1261:   //sgsDeleteIniFile ()
  1262:   //  設定ファイルを削除する
  1263:   public static void sgsDeleteIniFile () {
  1264:     if (sgsIniFile.isFile ()) {  //XEiJ.iniがある
  1265:       if (sgsIniFile.delete ()) {  //XEiJ.iniを削除する。削除できた
  1266:         System.out.println (sgsIniPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
  1267:       } else {  //削除できない
  1268:         System.out.println (sgsIniPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
  1269:         return;
  1270:       }
  1271:     }
  1272:     String bakPath = sgsIniPath + ".bak";
  1273:     File bakFile = new File (bakPath);
  1274:     if (bakFile.isFile ()) {  //XEiJ.ini.bakがある
  1275:       if (bakFile.delete ()) {  //XEiJ.ini.bakを削除する。削除できた
  1276:         System.out.println (bakPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
  1277:       } else {  //削除できない
  1278:         System.out.println (bakPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
  1279:         return;
  1280:       }
  1281:     }
  1282:     String tmpPath = sgsIniPath + ".tmp";
  1283:     File tmpFile = new File (tmpPath);
  1284:     if (tmpFile.isFile ()) {  //XEiJ.ini.tmpがある
  1285:       if (tmpFile.delete ()) {  //XEiJ.ini.tmpを削除する。削除できた
  1286:         System.out.println (tmpPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
  1287:       } else {  //削除できない
  1288:         System.out.println (tmpPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
  1289:         return;
  1290:       }
  1291:     }
  1292:     if (sgsIniParentDirectory != null &&
  1293:         sgsIniParentDirectory.isDirectory ()) {  //AppData/Roaming/XEiJがある
  1294:       if (sgsIniParentDirectory.delete ()) {  //AppData/Roaming/XEiJの削除を試みる。ディレクトリが空でなければ失敗する。削除できた
  1295:         System.out.println (sgsIniParentPath + (Multilingual.mlnJapanese ? " を削除しました" : " was removed"));
  1296:       } else {  //削除できない
  1297:         System.out.println (sgsIniParentPath + (Multilingual.mlnJapanese ? " を削除できません" : " cannot be removed"));
  1298:       }
  1299:     }
  1300:   }  //sgsDeleteIniFile()
  1301: 
  1302: 
  1303: 
  1304: }  //class Settings
  1305: 
  1306: 
  1307: