OSDN Git Service

DTXManiaソリューション、DTXManiaプロジェクト、DTXCreatorプロジェクト、FDKプロジェクトについて英語化。
[dtxmania/dtxmania.git] / DTXCreator / コード / 06.汎用 / Cファイル選択・パス変換.cs
diff --git a/DTXCreator/コード/06.汎用/Cファイル選択・パス変換.cs b/DTXCreator/コード/06.汎用/Cファイル選択・パス変換.cs
new file mode 100644 (file)
index 0000000..391e14e
--- /dev/null
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+
+namespace DTXCreator.汎用
+{
+       public class Cファイル選択_パス変換
+       {
+               public static bool b絶対パスである( string strパス )
+               {
+                       try
+                       {
+                               new Uri( strパス );
+                       }
+                       catch
+                       {
+                               return false;
+                       }
+                       return true;
+               }
+               public static string str基点からの相対パスに変換して返す( string str変換対象の絶対パス, string str基点となる絶対パス )
+               {
+                       if( str基点となる絶対パス == "" )
+                       {
+                               return str変換対象の絶対パス;
+                       }
+                       if( str変換対象の絶対パス == "" )
+                       {
+                               return "";
+                       }
+                       Uri uri = new Uri( str基点となる絶対パス );
+                       return Uri.UnescapeDataString( uri.MakeRelativeUri( new Uri( str変換対象の絶対パス ) ).ToString() ).Replace( '/', '\\' );
+               }
+               public static string str指定されたファイルの存在するフォルダを絶対パスで返す( string strファイルのパス, string strパスが相対の場合の基点絶対パス )
+               {
+                       if( !b絶対パスである( strファイルのパス ) )
+                       {
+                               strファイルのパス = strパスが相対の場合の基点絶対パス + strファイルのパス;
+                       }
+                       string directoryName = Path.GetDirectoryName( strファイルのパス );
+                       if( directoryName == null )
+                       {
+                               return @"\";
+                       }
+                       if( !directoryName.EndsWith( @"\" ) )
+                       {
+                               directoryName = directoryName + @"\";
+                       }
+                       return directoryName;
+               }
+       }
+}