123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
-
- using System.IO;
- using System.Diagnostics;
- using System;
- using System.Timers;
- namespace Uninpho.Tools
- {
- public class Utility
- {
-
-
-
-
-
-
- public static void SetTimeout(double interval, Action action)
- {
- System.Timers.Timer timer = new System.Timers.Timer(interval);
- timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
- {
- timer.Enabled = false;
- action();
- };
- timer.Enabled = true;
- }
-
-
-
-
-
- public static void SetInterval(double interval, Action<ElapsedEventArgs> action)
- {
- System.Timers.Timer timer = new System.Timers.Timer(interval);
- timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
- {
- action(e);
- };
- timer.Enabled = true;
- }
-
-
-
-
- public static string GetTemPath(string dbPath)
- {
- string temPath = Path.Combine(Path.GetDirectoryName(dbPath),"temp");
- if (!Directory.Exists(temPath))
- {
- Directory.CreateDirectory(temPath);
- File.SetAttributes(temPath, FileAttributes.Hidden | FileAttributes.System);
- }
- return temPath;
- }
-
-
-
-
-
- public static string GetAssemblyPath()
- {
- string _CodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
- _CodeBase = _CodeBase.Substring(8, _CodeBase.Length - 8);
- string[] arrSection = _CodeBase.Split(new char[] { '/' });
- string _FolderPath = "";
- for (int i = 0; i < arrSection.Length - 1; i++)
- {
- _FolderPath += arrSection[i] + "/";
- }
- return _FolderPath;
- }
-
-
-
-
- public static string GetDataPath()
- {
- string tileDataDir = "";
- string _CodeBase = GetAssemblyPath();
- tileDataDir = System.IO.Path.Combine(System.IO.Directory.GetParent(_CodeBase).Parent.FullName, "data");
- if (!System.IO.Directory.Exists(tileDataDir))
- Directory.CreateDirectory(tileDataDir);
- return tileDataDir;
- }
-
-
-
-
-
- public static Process CallExe(string exePath, string parameters)
- {
- Process process = new System.Diagnostics.Process();
- process.StartInfo.FileName = exePath;
- process.StartInfo.Arguments = parameters;
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.RedirectStandardOutput = false;
- process.EnableRaisingEvents = true;
-
- return process;
-
- }
-
-
-
-
-
- public static string[] GetFiles(string dir, string filter,SearchOption option = SearchOption.TopDirectoryOnly)
- {
- return Directory.GetFiles(dir, filter, option);
- }
-
- }
- }
|