当前位置: 首页>>代码示例>>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;未经允许,请勿转载。