/* * Karinto Library Project * * This software is distributed under a zlib-style license. * See license.txt for more information. */ using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; using System.Text; namespace Karinto { /// /// フルパスを動的に解決するパス /// public class FilePath { private string path; private string suffix; private static string WorkDirectory; public static void SetDirectory(string path) { WorkDirectory = (path == null) ? "" : path; } public FilePath(string path) : this(path, "") { } public FilePath(string path, string suffix) { this.path = (path == null) ? "" : path; this.suffix = (suffix == null) ? "" : suffix; } public static implicit operator string(FilePath fp) { if (fp == null) return ""; return fp.ToString(); } public static implicit operator FilePath(string s) { return new FilePath(s); } public void SetSuffix(string suffix) { this.suffix = (suffix == null) ? "" : suffix; } public override string ToString() { string ext = Regex.Match(path, "\\.[^\\.]+$").Groups[0].Value; string fullpath = Regex.Replace(path, ext + "$", suffix + ext); if (File.Exists(WorkDirectory + "\\" + fullpath)) { fullpath = WorkDirectory + "\\" + fullpath; } return fullpath; } public bool Exists { get { return File.Exists( ToString() ); } } } }