public void loadJSON() { config = null; menu.DirectoryCheck(); //ファイルがない場合: 初期設定ファイルの生成 if (!File.Exists(jsonPath)) { config = new ImageViewerConfig(); makeJSON(); } //ファイルの読込を試行 try { //ファイルの内容を一括読み出し string jsonString = File.ReadAllText(jsonPath, new UTF8Encoding(false)); //設定クラスをJSONデコードして生成 config = JsonUtility.FromJson <ImageViewerConfig>(jsonString); //ファイルのバージョンが古い場合は、デフォルト設定にして警告(nullの可能性も考慮してtry内) if (config.jsonVer != jsonVerMaster) { menu.ShowDialogOKCancel(LanguageManager.config.jsonloaders.OLD_CONFIG_HEAD, "" + jsonPath + LanguageManager.config.jsonloaders.OLD_CONFIG_BODY, 3f, () => { //OK makeJSON(); }, () => { //キャンセル }); config = new ImageViewerConfig(); config.path1 = Directory.GetCurrentDirectory() + "\\img\\"; config.path2 = Directory.GetCurrentDirectory() + "\\img\\"; config.path3 = Directory.GetCurrentDirectory() + "\\img\\"; } } catch (System.Exception e) { //JSONデコードに失敗した場合 Debug.Log(e.ToString()); config = null; } //デコード失敗した場合は、デフォルト設定にして警告 if (config == null) { config = new ImageViewerConfig(); config.path1 = Directory.GetCurrentDirectory() + "\\img\\"; config.path2 = Directory.GetCurrentDirectory() + "\\img\\"; config.path3 = Directory.GetCurrentDirectory() + "\\img\\"; menu.ShowDialogOKCancel(LanguageManager.config.jsonloaders.CORRUPT_CONFIG_HEAD, "" + jsonPath + LanguageManager.config.jsonloaders.CORRUPT_CONFIG_BODY, 3f, () => { //OK makeJSON(); }, () => { //キャンセル }); } }
public void makeJSON() { //初期設定ファイルを生成 var c = new ImageViewerConfig(); c.path1 = Directory.GetCurrentDirectory() + "\\img\\"; c.path2 = Directory.GetCurrentDirectory() + "\\img\\"; c.path3 = Directory.GetCurrentDirectory() + "\\img\\"; var json = JsonUtility.ToJson(c); //初期設定ファイルを書き込み File.WriteAllText(jsonPath, json, new UTF8Encoding(false)); }
//ファイル一覧を取得し、画像を読み込む。あとがない場合は繰り返す public void loadImage() { loadJSON(); setPath(); if (!Directory.Exists(path)) { config = new ImageViewerConfig(); setPath(); path = Directory.GetCurrentDirectory() + "\\img\\"; menu.ShowDialogOKCancel(LanguageManager.config.showdialog.FOLDER_NOT_FOUND_TITLE, LanguageManager.config.showdialog.FOLDER_NOT_FOUND_BODY1 + jsonPath + LanguageManager.config.showdialog.FOLDER_NOT_FOUND_BODY2, 0.1f, () => { //OK makeJSON(); }, () => { //キャンセル }); return; } //ファイル一覧を取得 if (files == null) { if (!getList()) { return; } } if (files.Length == 0) { menu.ShowDialogOK(LanguageManager.config.showdialog.FILE_NOT_FOUND, "", 0.1f, () => { }); return; } if (no > files.Length - 1) { no = 0; } if (no < 0) { no = files.Length - 1; } ImageLoadLocal(files[no]); }