コード例 #1
0
        //────────────────────────────────────────

        /// <summary>
        /// 絶対パスが、ファイルシステムで使えるファイルパスの文字列の長さの制限を越えていれば真。
        /// </summary>
        /// <param name="newDirectoryPath">指定するものがない場合は、System.Windows.Forms.StartupPath を入れてください。</param>
        /// <param name="newHumanInputFilePath"></param>
        /// <param name="cur_Conf"></param>
        public static bool IsTooLong_Path(
            string folderpath_New,
            string filepath_Humaninput_New,
            Log_Reports log_Reports,
            Configurationtree_Node cur_Conf
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0);

            log_Method.BeginMethod(Info_Syntax.Name_Library, "Utility_Configurationtree_Filepath", "IsTooLong_Path", log_Reports);

            // フラグ。
            bool bFlagCheckPathTooLong = false;

            if (log_Reports.Successful)
            {
                // チェック。絶対パスにすることができればOK。
                Utility_Configurationtree_Filepath.ToFilepathabsolute(
                    folderpath_New,
                    filepath_Humaninput_New,
                    ref bFlagCheckPathTooLong,
                    true,        //ファイル名の長さが上限超過でも、正常処理扱いとします。
                    log_Reports, // out sErrorMsg,
                    cur_Conf
                    );
            }

            goto gt_EndMethod;
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(bFlagCheckPathTooLong);
        }
コード例 #2
0
        public void SetHumaninput(
            string filepath_Humaninput_New,
            Log_Reports log_Reports
            )
        {
            if (log_Reports.Successful)
            {
                // ダミー・フラグ。使いません。
                bool bDammyFlagCheckPathTooLong = false;

                // チェックするだけ。 絶対パスにすることができれば問題なし、そのままスルー。
                Utility_Configurationtree_Filepath.ToFilepathabsolute(
                    this.directory_Base,
                    filepath_Humaninput_New,
                    ref bDammyFlagCheckPathTooLong,
                    false,//ファイル名の長さが上限超過ならエラー
                    log_Reports,
                    this.Parent
                    );
            }

            if (log_Reports.Successful)
            {
                // 引数を受け入れます。
                this.humaninput = filepath_Humaninput_New;
            }

            goto gt_EndMethod;
            //
            //
gt_EndMethod:
            return;
        }
コード例 #3
0
        //────────────────────────────────────────

        /// <summary>
        /// 相対パスが設定されていた場合、その相対元となるディレクトリーへのパスです。
        /// そうでない場合は、System.Windows.Forms.StartupPath を入れてください。
        /// </summary>
        /// <param name="newDirectoryPath"></param>
        public void SetDirectory_Base(
            string sFolderpath_New,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0);

            log_Method.BeginMethod(Info_Syntax.Name_Library, this, "SetSDirectory_Base", log_Reports);

            // ダミー・フラグ。使いません。
            bool bDammyFlagCheckPathTooLong = false;

            if (this.Cur_Configuration is Configurationtree_NodeFilepath)
            {
                Configurationtree_NodeFilepath cf_Fpath = ((Configurationtree_NodeFilepath)this.Cur_Configuration);

                // チェック。絶対パスにすることができればOK。
                Utility_Configurationtree_Filepath.ToFilepathabsolute(
                    sFolderpath_New,
                    cf_Fpath.GetHumaninput(),
                    ref bDammyFlagCheckPathTooLong,
                    false,       //ファイル名の長さが上限超過ならエラー
                    log_Reports, //out sErrorMsg,
                    this.Cur_Configuration
                    );
                if (!log_Reports.Successful)
                {
                    // 既エラー。
                    goto gt_EndMethod;
                }

                cf_Fpath.SetDirectory_Base(sFolderpath_New);
            }
            else
            {
                // エラー
                if (log_Reports.CanCreateReport)
                {
                    Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                    r.SetTitle("▲エラー903!", log_Method);

                    Log_TextIndented s = new Log_TextIndentedImpl();
                    s.Append(Environment.NewLine);
                    s.Append("#GetSAbsoluteFilePath:型が違います。[" + this.Cur_Configuration.GetType().Name + "]");

                    r.Message = s.ToString();
                    log_Reports.EndCreateReport();
                }
            }

            //
            //
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return;
        }
コード例 #4
0
        //────────────────────────────────────────

        public static bool IsTooLong_Path(
            string filepath_Humaninput_New,
            Log_Reports log_Reports,
            Configurationtree_Node cur_Conf
            )
        {
            return(Utility_Configurationtree_Filepath.IsTooLong_Path(
                       "",
                       filepath_Humaninput_New,
                       log_Reports,// out sErrorMsg,
                       cur_Conf
                       ));
        }
コード例 #5
0
        //────────────────────────────────────────

        /// <summary>
        /// パスを設定します。相対パス、絶対パスの違いを吸収するためのものです。
        /// </summary>
        /// <param name="sFopath_New">フォルダーパス。指定するものがない場合は、System.Windows.Forms.StartupPath を入れてください。</param>
        /// <param name="sFpath_Newhumaninput">ファイルパス。</param>
        public void InitPath(
            string sFopath_New,
            string sFpath_Newhumaninput,
            Log_Reports log_Reports
            )
        {
            // ダミー・フラグ。使いません。
            bool bDammyFlagCheckPathTooLong = false;

            if (log_Reports.Successful)
            {
                // チェック。絶対パスにすることができればOK。
                Utility_Configurationtree_Filepath.ToFilepathabsolute(
                    sFopath_New,
                    sFpath_Newhumaninput,
                    ref bDammyFlagCheckPathTooLong,
                    false,       //ファイル名の長さが上限超過ならエラー
                    log_Reports, //out out_sErrorMsg,
                    this
                    );
            }

            if (log_Reports.Successful)
            {
                this.SetDirectory_Base(sFopath_New);
            }

            if (log_Reports.Successful)
            {
                this.SetHumaninput(
                    sFpath_Newhumaninput,
                    log_Reports
                    );
            }

            goto gt_EndMethod;
            //
            //
gt_EndMethod:
            return;
        }
コード例 #6
0
        //────────────────────────────────────────

        public static string ToFilepathabsolute(
            string humaninput,
            ref bool ref_isTooLong_Path,
            bool isSafe_TooLong_Path,
            Log_Reports log_Reports,
            Configurationtree_Node cur_Conf
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0);

            log_Method.BeginMethod(Info_Syntax.Name_Library, "Utility_Configurationtree_Filepath", "ToFilepathabsolute③", log_Reports);

            string sResult;

            if (log_Reports.Successful)
            {
                sResult = Utility_Configurationtree_Filepath.ToFilepathabsolute(
                    "",
                    humaninput,
                    ref ref_isTooLong_Path,
                    isSafe_TooLong_Path,
                    log_Reports,//out sErrorMsg,
                    cur_Conf
                    );
            }
            else
            {
                sResult = "";
            }

            goto gt_EndMethod;
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(sResult);
        }
コード例 #7
0
        //────────────────────────────────────────

        /// <summary>
        /// 「ディレクトリー」と「入力値」の2つを入力すると、「絶対パス」を返します。
        ///
        /// ──────────
        ///
        /// 未設定の場合は、空文字列を返します。
        /// ※bug:フォルダーパスの場合も空文字列になる??
        ///
        /// ・ファイルパスとして利用できない文字や、予約語が含まれていると例外を投げます。
        /// ・絶対パスの文字列の長さが、ファイルシステムで使える制限を越えると例外を投げます。
        ///
        /// もし、設定されたパスが相対パスだった場合に、ベース・パスが設定されていなければ、
        /// 起動「.exe」のあったパスが頭に付く。
        /// </summary>
        /// <param name="baseDirectory"></param>
        /// <param name="humanInputText"></param>
        /// <param name="flagCheckPathTooLong">絶対パスの文字列の長さが、ファイルシステムで使える上限を超えていた場合に真、そうでない場合 偽にセットされます。</param>
        /// <param name="okPathTooLong">絶対パスの文字列の長さが、ファイルシステムで使える上限を超えていた場合に、「正常扱いにするなら」真、「エラー扱いにするなら」偽。</param>
        /// <param name="cur_Conf">デバッグ用情報。人間オペレーターが修正するべき箇所などの情報。</param>
        /// <returns></returns>
        public static string ToFilepathabsolute(
            string directory_Base,
            string humaninput,
            ref bool ref_IsTooLong_Path,
            bool isSafe_TooLong_Path,
            Log_Reports log_Reports,
            Configuration_Node cur_Conf
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0);

            log_Method.BeginMethod(Info_Syntax.Name_Library, "Utility_Configurationtree_Filepath", "ToFilepathabsolute②", log_Reports);
            //
            //

            //
            // 修正履歴(2009-12-02)
            //
            // ・カレント・ディレクトリの移動を使ったコードを書いてはいけない。
            //   MS-DOSの名残り?
            //
            // ・起動「.exe」のディレクトリは Application.StartupPath で取得できる。
            //
            // ・備考:
            // System.IO.Directory.GetCurrentDirectory()は、
            // 「プロセスが開始されたディレクトリ」を返すので、
            // openFileDialogで開いたディレクトリを返すこともある。
            //
            // System.IO.Path.GetFullPath(path)も同じ。

            Exception err_Excp;

            string result_Filepath;//ファイルパス

            // フラグのクリアー。
            ref_IsTooLong_Path = false;

            //
            // 人間がCSVファイルに記述しているファイル・パス。
            //
            // 「絶対パス」「相対パス」のどちらでも指定されます。
            //
            string filepath_Source = humaninput.Trim();

            if ("" == filepath_Source)
            {
                // 未設定の場合。
                result_Filepath = "";//ファイルパスとしては使えない文字列。
                goto gt_EndMethod;
            }

            // 「絶対パス」か、「相対パス」かを判断します。
            bool isRooted_Path = Utility_Configurationtree_Filepath.IsRooted_Path(
                filepath_Source,
                log_Reports
                );

            if (!log_Reports.Successful)
            {
                // 既エラー。
                result_Filepath = "";//ファイルパスとしては使えない文字列。
                goto gt_EndMethod;
            }

            if (!isRooted_Path)
            {
                // 相対パスの場合

                // 「相対パス」に「ベース・ディレクトリー文字列」を連結して、「絶対パス」に変換します。

                if ("" != directory_Base)
                {
                    // 相対パスの相対元となるディレクトリーが設定されていれば。

                    if (!directory_Base.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        filepath_Source = directory_Base + Path.DirectorySeparatorChar + filepath_Source;
                    }
                    else
                    {
                        filepath_Source = directory_Base + filepath_Source;
                    }
                }
                else
                {
                    // 起動「.exe」のあったパスを、相対の元となるディレクトリーとします。

                    if (!directory_Base.EndsWith(Path.DirectorySeparatorChar.ToString()))
                    {
                        filepath_Source = Application.StartupPath + Path.DirectorySeparatorChar + filepath_Source;
                    }
                    else
                    {
                        filepath_Source = Application.StartupPath + filepath_Source;
                    }
                }
            }

            // ここで、パスは 絶対パスに変換されています。

            try
            {
                // カレントディレクトリは使わない。

                // 絶対パスの場合、GetFullPathを通す必要はないが、
                // ファイルパスに使えない文字列を判定するために、
                // 例外を返すメソッドを使っています。
                result_Filepath = System.IO.Path.GetFullPath(filepath_Source);
            }
            catch (ArgumentException e)
            {
                // 指定のファイルパスに「*」など、ファイルパスとして使えない文字列が含まれていた場合など。

                result_Filepath = "";//ファイルパスとしては使えない文字列。

                err_Excp = e;
                goto gt_Error_ArgumentException;
            }
            catch (PathTooLongException e)
            {
                // ディレクトリーの文字数が、制限数を超えた場合などのエラー。

                result_Filepath = "";//ファイルパスとしては使えない文字列。

                if (isSafe_TooLong_Path)
                {
                    // 正常処理扱いとします。
                }
                else
                {
                    // 異常扱いとします。

                    err_Excp = e;
                    goto gt_Error_PathTooLongException;
                }


                ref_IsTooLong_Path = true;
            }
            catch (NotSupportedException e)
            {
                //パスのフォーマットが間違っているなどのエラー。
                result_Filepath = "";//ファイルパスとしては使えない文字列。
                err_Excp        = e;
                goto gt_Error_NotSupportedException;
            }
            catch (Exception e)
            {
                // それ以外のエラー。
                result_Filepath = "";//ファイルパスとしては使えない文字列。
                err_Excp        = e;
                goto gt_Error_Exception;
            }

            goto gt_EndMethod;
            //
            #region 異常系
            //────────────────────────────────────────
gt_Error_ArgumentException:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー107!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append(Environment.NewLine);
                s.Append("使えないファイルパスです。[");
                s.Append(filepath_Source);
                s.Append("] :");

                s.Append(err_Excp.Message);
                cur_Conf.ToText_Locationbreadcrumbs(s);

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_PathTooLongException:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー108!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append(Environment.NewLine);
                s.Append("エラー 入力パス=[" + filepath_Source + "]:(" + err_Excp.GetType().Name + ") ");

                s.Append(err_Excp.Message);
                cur_Conf.ToText_Locationbreadcrumbs(s);

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_NotSupportedException:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー109!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append(Environment.NewLine);
                s.Append("ファイルパスが間違っているかもしれません。");
                s.Newline();
                s.AppendI(1, "入力パス=[" + filepath_Source + "]");
                s.Newline();

                // ヒント
                s.Append(r.Message_SException(err_Excp));
                cur_Conf.ToText_Locationbreadcrumbs(s);

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_Exception:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー109!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append(Environment.NewLine);
                s.Append("エラー 入力パス=[" + filepath_Source + "]");
                s.Newline();

                // ヒント
                s.Append(r.Message_SException(err_Excp));
                cur_Conf.ToText_Locationbreadcrumbs(s);

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(result_Filepath);
        }
コード例 #8
0
        //────────────────────────────────────────

        /// <summary>
        /// 絶対パスを取得します。
        ///
        /// 未設定の場合は、空文字列を返します。
        ///
        /// ・ファイルパスとして利用できない文字や、予約語が含まれていると例外を投げます。
        /// ・絶対パスの文字列の長さが、ファイルシステムで使える制限を越えると例外を投げます。
        ///
        /// 設定されたパスが相対パスだった場合に、ベース・パスが設定されていなければ、
        /// 起動「.exe」のあったパスが頭に付く。
        /// </summary>
        /// <returns></returns>
        public override string Execute4_OnExpressionString(
            EnumHitcount request,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

            log_Method.BeginMethod(Info_Syntax.Name_Library, this, "Execute4_OnExpressionString", log_Reports);
            //
            //

            // 絶対パスにして返します。

            string sFpath;

            if (this.Cur_Configuration is Configurationtree_NodeFilepath)
            {
                Configurationtree_NodeFilepath cf_Fpath = (Configurationtree_NodeFilepath)this.Cur_Configuration;

                bool bCheckPathTooLong = false;

                if (log_Reports.Successful)
                {
                    sFpath = Utility_Configurationtree_Filepath.ToFilepathabsolute(
                        this.Directory_Base,
                        cf_Fpath.GetHumaninput(), //this.SHumanInput相当
                        ref bCheckPathTooLong,    //ファイル名の長さチェックは、もう済んでいるものとして、行いません。
                        false,                    //ファイル名の長さが上限超過ならエラー
                        log_Reports,              //out sErrorMsg,
                        this.Cur_Configuration
                        );
                }
                else
                {
                    sFpath = "";
                }
            }
            else
            {
                // エラー。
                sFpath = "";
                if (log_Reports.CanCreateReport)
                {
                    Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                    r.SetTitle("▲エラー901!", log_Method);

                    Log_TextIndented s = new Log_TextIndentedImpl();
                    s.Append(Environment.NewLine);
                    s.Append("#GetSAbsoluteFilePath:型が違います。[" + this.Cur_Configuration.GetType().Name + "]");

                    r.Message = s.ToString();
                    log_Reports.EndCreateReport();
                }
            }

            goto gt_EndMethod;
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(sFpath);
        }