當前位置: 首頁>>代碼示例>>C#>>正文


C# DriveInfo.Contains方法代碼示例

本文整理匯總了C#中System.IO.DriveInfo.Contains方法的典型用法代碼示例。如果您正苦於以下問題:C# DriveInfo.Contains方法的具體用法?C# DriveInfo.Contains怎麽用?C# DriveInfo.Contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.IO.DriveInfo的用法示例。


在下文中一共展示了DriveInfo.Contains方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

 private static void Main()
 {
     Log.AllowLogging();
     try
     {
         var javaPath = string.Empty;
         var exePath = PathEx.Combine("%CurDir%\\JDownloader_v2.0\\JDownloader2.exe");
         var envVar = EnvironmentEx.GetVariableValue("CurDir");
         if (!File.Exists(exePath))
         {
             var drive = new DriveInfo(envVar).RootDirectory.Root.Name;
             var JavaDir = drive;
             foreach (var dirName in envVar.Split('\\'))
                 try
                 {
                     if (drive.Contains(dirName))
                         continue;
                     JavaDir = Path.Combine(JavaDir, dirName);
                     string tmpDir;
                     if (Environment.Is64BitOperatingSystem)
                     {
                         tmpDir = Path.Combine(JavaDir, "CommonFiles\\Java64");
                         if (Directory.Exists(tmpDir))
                             foreach (var file in Directory.GetFiles(tmpDir, "javaw.exe", SearchOption.AllDirectories))
                             {
                                 JavaDir = tmpDir;
                                 javaPath = file;
                                 break;
                             }
                     }
                     tmpDir = Path.Combine(JavaDir, "CommonFiles\\Java64");
                     if (!File.Exists(tmpDir))
                         continue;
                     if (!Directory.Exists(tmpDir))
                         continue;
                     foreach (var file in Directory.GetFiles(tmpDir, "javaw.exe", SearchOption.AllDirectories))
                     {
                         JavaDir = tmpDir;
                         javaPath = file;
                         break;
                     }
                 }
                 catch (Exception ex)
                 {
                     Log.Write(ex);
                 }
             if (!File.Exists(javaPath))
             {
                 if (File.Exists($"{exePath}.disabled"))
                     File.Move($"{exePath}.disabled", exePath);
                 var updExePath = PathEx.Combine("%CurDir%\\JDownloader_v2.0\\JDownloader2Update.exe");
                 if (File.Exists($"{updExePath}.disabled"))
                     File.Move($"{updExePath}.disabled", updExePath);
             }
         }
         if (!File.Exists(javaPath) && !File.Exists(exePath))
         {
             MessageBox.Show(@"Java Portable not found!", @"JDownloader 2 Portable", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         var jDownloader = Path.Combine("%CurDir%\\JDownloader_v2.0\\JDownloader.jar");
         if (!File.Exists(jDownloader))
         {
             MessageBox.Show(@"JDownloader 2 not found!", @"JDownloader 2 Portable", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         bool newInstance;
         using (new Mutex(true, Process.GetCurrentProcess().ProcessName, out newInstance))
         {
             var jdDir = Path.GetDirectoryName(jDownloader);
             if (newInstance)
             {
                 var jreUsageDir = PathEx.Combine("%UserProfile%\\.oracle_jre_usage");
                 if (!Directory.Exists(jreUsageDir))
                     Directory.CreateDirectory(jreUsageDir);
                 Data.SetAttributes(jreUsageDir, FileAttributes.Hidden);
                 if (File.Exists(exePath))
                 {
                     using (var p = ProcessEx.Start(exePath, EnvironmentEx.CommandLine(false), false, false))
                         if (!p?.HasExited == true)
                             p?.WaitForExit();
                 }
                 else
                 {
                     using (var p = ProcessEx.Start(javaPath, jdDir, $"-jar \"{jDownloader}\" {EnvironmentEx.CommandLine(false)}".Trim(), false, false))
                         if (!p?.HasExited == true)
                             p?.WaitForExit();
                 }
                 if (Directory.Exists(jreUsageDir))
                     Directory.Delete(jreUsageDir, true);
             }
             else
             {
                 if (File.Exists(exePath))
                     ProcessEx.Start(exePath, EnvironmentEx.CommandLine(false));
                 else
                     ProcessEx.Start(javaPath, jdDir, $"-jar \"{jDownloader}\" {EnvironmentEx.CommandLine(false)}".Trim());
             }
         }
     }
//.........這裏部分代碼省略.........
開發者ID:Si13n7,項目名稱:PortableAppsSuite,代碼行數:101,代碼來源:Program.cs


注:本文中的System.IO.DriveInfo.Contains方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。