Browse Source

ISCSIConsole: Detect platform in runtime and add .NET Framework 4.7.2 target for Mono

TalAloni 4 years ago
parent
commit
2365a52fa4

+ 11 - 15
ISCSIConsole/AddTargetForm.cs

@@ -23,15 +23,16 @@ namespace ISCSIConsole
         public AddTargetForm()
         {
             InitializeComponent();
-#if Win32
-            btnAddPhysicalDisk.Visible = true;
-            btnAddVolume.Visible = true;
-            if (!SecurityHelper.IsAdministrator())
+            if (RuntimeHelper.IsWin32)
             {
-                btnAddPhysicalDisk.Enabled = false;
-                btnAddVolume.Enabled = false;
+                btnAddPhysicalDisk.Visible = true;
+                btnAddVolume.Visible = true;
+                if (!SecurityHelper.IsAdministrator())
+                {
+                    btnAddPhysicalDisk.Enabled = false;
+                    btnAddVolume.Enabled = false;
+                }
             }
-#endif
         }
 
         private void AddTargetForm_Load(object sender, EventArgs e)
@@ -76,19 +77,16 @@ namespace ISCSIConsole
 
         private void btnAddPhysicalDisk_Click(object sender, EventArgs e)
         {
-#if Win32
             SelectPhysicalDiskForm selectPhysicalDisk = new SelectPhysicalDiskForm();
             DialogResult result = selectPhysicalDisk.ShowDialog();
             if (result == DialogResult.OK)
             {
                 AddDisk(selectPhysicalDisk.SelectedDisk);
             }
-#endif
         }
 
         private void btnAddVolume_Click(object sender, EventArgs e)
         {
-#if Win32
             SelectVolumeForm selectVolume = new SelectVolumeForm();
             DialogResult result = selectVolume.ShowDialog();
             if (result == DialogResult.OK)
@@ -96,7 +94,6 @@ namespace ISCSIConsole
                 VolumeDisk volumeDisk = new VolumeDisk(selectVolume.SelectedVolume, selectVolume.IsReadOnly);
                 AddDisk(volumeDisk);
             }
-#endif
         }
 
         private void AddDisk(Disk disk)
@@ -111,16 +108,15 @@ namespace ISCSIConsole
             {
                 description = "RAM Disk";
             }
-#if Win32
-            else if (disk is PhysicalDisk)
+            else if (disk is PhysicalDisk) // Win32 only
             {
                 description = String.Format("Physical Disk {0}", ((PhysicalDisk)disk).PhysicalDiskIndex);
             }
-            else if (disk is VolumeDisk)
+            else if (disk is VolumeDisk) // Win32 only
             {
                 description = String.Format("Volume");
             }
-#endif
+
             ListViewItem item = new ListViewItem(description);
             item.SubItems.Add(sizeString);
             listDisks.Items.Add(item);

+ 2 - 4
ISCSIConsole/Helpers/LockUtils.cs

@@ -32,8 +32,7 @@ namespace ISCSIConsole
             {
                 ((RAMDisk)disk).Free();
             }
-#if Win32
-            else if (disk is PhysicalDisk)
+            else if (disk is PhysicalDisk) // Win32 only
             {
                 if (!DiskAccessLibrary.LogicalDiskManager.DynamicDisk.IsDynamicDisk(disk))
                 {
@@ -47,7 +46,7 @@ namespace ISCSIConsole
                     }
                 }
             }
-            else if (disk is VolumeDisk)
+            else if (disk is VolumeDisk) // Win32 only
             {
                 bool skippedLock = (Environment.OSVersion.Version.Major >= 6 && VolumeInfo.IsOffline(((VolumeDisk)disk).Volume));
                 if (!skippedLock)
@@ -59,7 +58,6 @@ namespace ISCSIConsole
                     }
                 }
             }
-#endif
         }
     }
 }

+ 19 - 0
ISCSIConsole/Helpers/RuntimeHelper.cs

@@ -0,0 +1,19 @@
+using System.Runtime.InteropServices;
+
+namespace ISCSIConsole
+{
+    public class RuntimeHelper
+    {
+        public static bool IsWin32
+        {
+            get
+            {
+#if NET472 || NETCOREAPP
+                return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
+#else
+                return true;
+#endif
+            }
+        }
+    }
+}

+ 1 - 0
ISCSIConsole/ISCSIConsole.VS2005.csproj

@@ -96,6 +96,7 @@
     </EmbeddedResource>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Helpers\RuntimeHelper.cs" />
     <Compile Include="Win32\SecurityHelper.cs" />
     <Compile Include="Win32\SelectPhysicalDiskForm.cs">
       <SubType>Form</SubType>

+ 1 - 1
ISCSIConsole/ISCSIConsole.csproj

@@ -2,7 +2,7 @@
 
   <PropertyGroup>
     <OutputType>WinExe</OutputType>
-    <TargetFrameworks>net20;net40;netcoreapp3.1</TargetFrameworks>
+    <TargetFrameworks>net20;net40;net472;netcoreapp3.1</TargetFrameworks>
     <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
     <Version>1.5.1</Version>
     <UseWindowsForms>true</UseWindowsForms>

+ 2 - 3
ISCSIConsole/MainForm.cs

@@ -48,12 +48,11 @@ namespace ISCSIConsole
             comboIPAddress.DisplayMember = "Key";
             comboIPAddress.ValueMember = "Value";
             lblStatus.Text = "Author: Tal Aloni (tal.aloni.il@gmail.com)";
-#if Win32
-            if (!SecurityHelper.IsAdministrator())
+
+            if (RuntimeHelper.IsWin32 && !SecurityHelper.IsAdministrator())
             {
                 lblStatus.Text = "Some features require administrator privileges and have been disabled";
             }
-#endif
         }
 
         private void btnStart_Click(object sender, EventArgs e)