/// <summary>
        /// 指定された月の日記ファイルを読み込んで、
        /// 日付をキーにした連想配列に入れて返します。
        /// 読み込む量は、先頭の10行、または1024文字まで。
        ///
        ///   連想配列["yyyyMMdd"] = テキスト
        ///
        /// 日記ファイルのパス
        /// diary/{yyyy}/{MM}/{yyyyMMdd}.txt
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <returns></returns>
        private Map <string, string> GetDiaryData(int year, int month)
        {
            var map = new Map <string, string>(); //キー:yyyyMMdd 値:先頭の10行
            var enc = Encoding.GetEncoding(932);

            //データフォルダのパスを作成します。{_dataDir}/yyyy/MM
            var dataDirPath = GetDataDirPath(year, month);

            //月末を取得します
            int endDay = DateTimeUtils.GetEndDate(year, month).Day;

            //1日 ~ 月末でループします
            for (int day = 1; day <= endDay; day++)
            {
                //日記ファイルの有無を確認します
                var yyyyMMdd = year + month.ToString("00") + day.ToString("00");
                var path     = FileUtils.AppendPath(dataDirPath, yyyyMMdd + ".txt");
                if (File.Exists(path) == false)
                {
                    continue;
                }

                //ファイルが存在する場合、先頭の10行を読み込みます
                var list = TextFileUtils.ReadTopLines(path, enc, 10);

                //読み込んだテキストを連想配列に設定します
                map[yyyyMMdd] = StringUtils.Left(string.Join("\n", list).Trim(), 1024);
            }

            return(map);
        }
Exemple #2
0
        // =================================================================================
        /// Reads the JSON root object from the given file path.
        ///
        /// @param filePath The file path from which to read.
        /// @return The JSON root object. _Null_ is return on error.
        ///
        public static JObject Read(string filePath, bool declareError = false)
        {
            var jsonData = TextFileUtils.ReadFile(filePath);

            if (string.IsNullOrEmpty(jsonData))
            {
                if (declareError)
                {
                    Debug.LogWarning("iCanScript: Unable to read file at=> " + filePath);
                }
                return(null);
            }
            // -- Decode JSON string. --
            JObject root = JSON.GetRootObject(jsonData);

            if (root.isNull)
            {
                if (declareError)
                {
                    Debug.LogWarning("iCanScript: JSON file corruption at=> " + filePath);
                }
                return(null);
            }
            return(root);
        }
Exemple #3
0
        // =================================================================================
        /// Writes using JSON pretty print the given object into the file at the given path.
        ///
        /// @param filePath The file path in which to write.
        /// @param fileData An object to be encoded in JSON format.
        /// @return _true_ if the file was written. _false_ otherwise.
        ///
        public static bool PrettyWrite(string filePath, System.Object fileData)
        {
            var jsonRoot = JObject.Build(fileData);
            var jsonData = JSONPrettyPrint.Print(jsonRoot.Encode(), 80);

            return(TextFileUtils.WriteFile(filePath, jsonData));
        }
Exemple #4
0
        // =================================================================================
        /// Writes the given object into the file at the given path.
        ///
        /// @param filePath The file path in which to write.
        /// @param fileData An object to be encoded in JSON format.
        /// @return _true_ if the file was written. _false_ otherwise.
        ///
        public static bool Write(string filePath, System.Object fileData)
        {
            var jsonRoot = JObject.Build(fileData);
            var jsonData = jsonRoot.Encode();

            return(TextFileUtils.WriteFile(filePath, jsonData));
        }
        //初期処理を行います
        public bool Initialize(PluginCreateParam param)
        {
            //指定されたファイルがある場合は、ファイルを開きます
            if (FileUtils.Exists(param.Path))
            {
                //指定されたパスの先頭の1行を読み込みます
                var lines = TextFileUtils.ReadTopLines(param.Path, Encoding.UTF8, 1);
                try {
                    var path = lines[0].Trim();

                    //OSで指定されている方法でファイルを開きます
                    Process.Start(path);
                } catch (Exception ex) {
                    MsgBoxUtils.ShowErrorMsgBox(ex.Message);
                }
            }

            //false を返してプラグインを破棄させます
            return(false);
        }
Exemple #6
0
        // ----------------------------------------------------------------------
        /// Writes or overwrites the CSharp code file.
        ///
        /// @param folderPath The absolute path of the code generation folder.
        /// @param className The name of the type/file.
        /// @param code The code to be put into the file.
        ///
        public static void WriteCSharpFile(string folderPath, string className, string code)
        {
            var filePath = folderPath + "/" + className + kFileExtension;

            TextFileUtils.WriteFile(filePath, code);
        }