Skip to content

Commit

Permalink
Version 0.5b
Browse files Browse the repository at this point in the history
  • Loading branch information
XyLe-GBP committed Sep 3, 2023
1 parent a586ca9 commit 70a12f7
Show file tree
Hide file tree
Showing 10 changed files with 1,585 additions and 501 deletions.
132 changes: 132 additions & 0 deletions src/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Xml;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Management;

namespace mca_coh_gui.src
{
Expand Down Expand Up @@ -124,6 +125,33 @@ public static string SFDRandomNumber()
return dt.Year + "-" + dt.Month + "-" + dt.Day + "-" + dt.Hour + "-" + dt.Minute + "-" + dt.Second;
}

/// <summary>
/// 指定したディレクトリ内のファイルも含めてディレクトリを削除する
/// </summary>
/// <param name="targetDirectoryPath">削除するディレクトリのパス</param>
public static void DeleteDirectory(string targetDirectoryPath)
{
if (!Directory.Exists(targetDirectoryPath))
{
return;
}

string[] filePaths = Directory.GetFiles(targetDirectoryPath);
foreach (string filePath in filePaths)
{
File.SetAttributes(filePath, FileAttributes.Normal);
File.Delete(filePath);
}

string[] directoryPaths = Directory.GetDirectories(targetDirectoryPath);
foreach (string directoryPath in directoryPaths)
{
DeleteDirectory(directoryPath);
}

Directory.Delete(targetDirectoryPath, false);
}

/// <summary>
/// 読み込みログを取得
/// </summary>
Expand Down Expand Up @@ -333,6 +361,7 @@ public static string DumpOrWriteKeyWithAutoKey(string file, int flag)
if (!IsGetInfo)
{
name = CurrentDir + @"\keys\key_" + SFDRandomNumber() + ".hex";
DumpTitle(Path.GetDirectoryName(name) + @"\title.txt");
}
else
{
Expand Down Expand Up @@ -455,6 +484,19 @@ public static string CheckRWByte(byte[] bytes)
return outp;
}

public static void DumpTitle(string file)
{
ProcessStartInfo? psi = new()
{
FileName = ResourcesDir + @"\mca-coh.exe",
Arguments = "-x title.txt " + file,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
};
Process? p = Process.Start(psi);
}

/// <summary>
/// ドングルのtitle.txtから情報を取得
/// </summary>
Expand Down Expand Up @@ -497,6 +539,32 @@ public static void GetDongleTitle(string[] buffers)
}
}

/// <summary>
/// 既に存在するtitle.txtから情報を取得
/// </summary>
/// <param name="path">title.txtのフルパス</param>
/// <param name="buffers">戻り値を格納するstring配列</param>
public static void GetDongleTitleAlreadyTxt(string path, string[] buffers)
{
using StreamReader sr = new(path);
string readtitle = sr.ReadToEnd();
sr.Close();
readtitle = readtitle.Replace("\n", "\r");
readtitle = readtitle.Trim('\r');
string[] readtitlelist = readtitle.Split('\r');
foreach (var item in readtitlelist)
{
if (item.Contains("MAKER:"))
{
buffers[0] = item.Replace("MAKER:", "");
}
if (item.Contains("TITLE:NM"))
{
buffers[1] = item.Replace("TITLE:NM", "NM");
}
}
}

/// <summary>
/// ドングルのタイトル番号からゲーム名を取得
/// </summary>
Expand Down Expand Up @@ -802,6 +870,70 @@ public static bool ByteArrayCompare(byte[] a, byte[] b)

return memcmp(a, b, new UIntPtr((uint)a.Length)) == 0;
}

public static bool Checkdriver()
{
System.Management.SelectQuery query = new("Win32_SystemDriver");
// 特定のドライバーを検索したい場合は query.Condition で条件を指定。
query.Condition = "Name = 'MemoryCard Adaptor with uusbd Driver (x64)'";
System.Management.ManagementObjectSearcher searcher = new(query);
var drivers = searcher.Get();
foreach (var d in drivers)
{
Debug.WriteLine("=== Properties ===");
foreach (var p in d.Properties)
{
// d.p["プロパティ名"] は d["プロパティ名"] と同じ
Debug.WriteLine(p.Name + ":" + p.Value);
}

Debug.WriteLine("=== System Propertides ===");
foreach (var p in d.SystemProperties)
{
Debug.WriteLine(p.Name + ":" + p.Value);
}
Debug.WriteLine("=== Qualifiers ===");
foreach (var q in d.Qualifiers)
{
Debug.WriteLine(q.Name + ":" + q.Value);
}
}
return false;
}

public static List<USBDeviceInfo> GetUSBDevices()
{
List<USBDeviceInfo> devices = new List<USBDeviceInfo>();

ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
collection = searcher.Get();

foreach (var device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceID"),
(string)device.GetPropertyValue("PNPDeviceID"),
(string)device.GetPropertyValue("Description")
));
}

collection.Dispose();
return devices;
}
}

public class USBDeviceInfo
{
public USBDeviceInfo(string deviceID, string pnpDeviceID, string description)
{
this.DeviceID = deviceID;
this.PnpDeviceID = pnpDeviceID;
this.Description = description;
}
public string DeviceID { get; private set; }
public string PnpDeviceID { get; private set; }
public string Description { get; private set; }
}

public class Config
Expand Down
3 changes: 2 additions & 1 deletion src/Forms/FormAbout.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.Net.NetworkInformation;
using static mca_coh_gui.Common;
using mca_coh_gui.src;
using static mca_coh_gui.src.Common;

namespace mca_coh_gui
{
Expand Down
Loading

0 comments on commit 70a12f7

Please sign in to comment.