123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using System.IO;
- namespace TriLib
- {
- public static class FileUtils
- {
- public static string GetShortFilename(string filename)
- {
- int num = filename.LastIndexOf("\\");
- if (num >= 0)
- {
- return filename.Substring(num + 1);
- }
- int num2 = filename.LastIndexOf("/");
- if (num2 >= 0)
- {
- return filename.Substring(num2 + 1);
- }
- return filename;
- }
- public static string GetFileDirectory(string filename)
- {
- int num = filename.LastIndexOf("\\");
- if (num >= 0)
- {
- return filename.Substring(0, num);
- }
- int num2 = filename.LastIndexOf("/");
- if (num2 >= 0)
- {
- return filename.Substring(0, num2);
- }
- return null;
- }
- public static string GetFilenameWithoutExtension(string filename)
- {
- int num = filename.LastIndexOf('.');
- if (num < 0)
- {
- return null;
- }
- int num2 = filename.LastIndexOf("\\");
- if (num2 >= 0)
- {
- return filename.Substring(num2, num);
- }
- int num3 = filename.LastIndexOf("/");
- if (num3 >= 0)
- {
- return filename.Substring(num3, num);
- }
- return null;
- }
- public static string GetFileExtension(string filename)
- {
- int num = filename.LastIndexOf('.');
- if (num < 0)
- {
- return null;
- }
- return filename.Substring(num).ToLowerInvariant();
- }
- public static string GetFilename(string path)
- {
- string fileName = Path.GetFileName(path);
- if (!(path == fileName))
- {
- return fileName;
- }
- int num = path.LastIndexOf("\\");
- if (num >= 0)
- {
- return path.Substring(num + 1);
- }
- int num2 = path.LastIndexOf("/");
- if (num2 >= 0)
- {
- return path.Substring(num2 + 1);
- }
- return path;
- }
- public static byte[] LoadFileData(string filename)
- {
- byte[] result;
- try
- {
- if (filename == null)
- {
- result = new byte[0];
- }
- else
- {
- result = File.ReadAllBytes(filename.Replace('\\', '/'));
- }
- }
- catch (Exception)
- {
- result = new byte[0];
- }
- return result;
- }
- }
- }
|