//ファイル一覧を取得し、テキストを読み込む。あとがない場合は繰り返す public void loadText() { loadJSON(); text.fontSize = config.fontsize; //フォントサイズを反映 if (!Directory.Exists(config.path)) { config = new TextViewerConfig(); menu.ShowDialogOKCancel(LanguageManager.config.showdialog.FOLDER_NOT_FOUND_TITLE, LanguageManager.config.showdialog.FOLDER_NOT_FOUND_BODY1 + jsonPath + LanguageManager.config.showdialog.FOLDER_NOT_FOUND_BODY2, 3f, () => { //OK makeJSON(); }, () => { //キャンセル }); return; } string[] files = Directory.GetFiles(config.path, "*.txt"); //帰ってくるのはフォルダ含む相対パス Array.Sort(files, (arg1, arg2) => { return(DateTime.Compare(File.GetLastWriteTime(arg2), File.GetLastWriteTime(arg1))); }); 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; } if (mode == "SJIS") { text.text = File.ReadAllText(files[no], Encoding.GetEncoding(932));//SJIS } else { text.text = File.ReadAllText(files[no], new UTF8Encoding(false)); } filename.text = Path.GetFileName(files[no]); /* * for (int i = 0; i < files.Length; i++) { * Debug.Log(i.ToString() + " : "+files[i]); * } */ }
public void loadJSON() { config = null; menu.DirectoryCheck(); //ファイルがない場合: 初期設定ファイルの生成 if (!File.Exists(jsonPath)) { config = new TextViewerConfig(); makeJSON(); } //ファイルの読込を試行 try { //ファイルの内容を一括読み出し string jsonString = File.ReadAllText(jsonPath, new UTF8Encoding(false)); //設定クラスをJSONデコードして生成 config = JsonUtility.FromJson <TextViewerConfig>(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 TextViewerConfig(); } } catch (System.Exception e) { //JSONデコードに失敗した場合 Debug.Log(e.ToString()); config = null; } //デコード失敗した場合は、デフォルト設定にして警告 if (config == null) { config = new TextViewerConfig(); menu.ShowDialogOKCancel(LanguageManager.config.jsonloaders.CORRUPT_CONFIG_HEAD, "" + jsonPath + LanguageManager.config.jsonloaders.CORRUPT_CONFIG_BODY, 3f, () => { //OK makeJSON(); }, () => { //キャンセル }); } }