Skip to content

Commit

Permalink
Handle combining data folders for WebGUI
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltris committed May 17, 2020
1 parent 0eaec16 commit cdcd037
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
31 changes: 23 additions & 8 deletions GK6X/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,12 +512,20 @@ private static void UpdateDataFiles(string srcDir)
}
}

// Create a merged 'driver' directory containing all the data from all distributors (for the WebGUI)
string combinedDriverDir = Path.Combine(srcDir, "driver_combined");

srcDir = GetDriverDir(srcDir);
if (string.IsNullOrEmpty(srcDir))
{
return;
}

if (!Directory.Exists(combinedDriverDir))
{
Directory.CreateDirectory(combinedDriverDir);
}

string dstDir = Path.Combine(Program.BasePath, "Data");
string leDir = Path.Combine(srcDir, "res", "data", "le");
string deviceDir = Path.Combine(srcDir, "device");
Expand Down Expand Up @@ -547,16 +555,20 @@ private static void UpdateDataFiles(string srcDir)
string additionalDeviceDir = Path.Combine(additionalDir, "device");
if (Directory.Exists(additionalDeviceDir))
{
CopyFilesRecursively(new DirectoryInfo(additionalDeviceDir), new DirectoryInfo(Path.Combine(dstDir, "device")));
CopyFilesRecursively(new DirectoryInfo(additionalDeviceDir), new DirectoryInfo(Path.Combine(dstDir, "device")), false);
string additionalModelListFile = Path.Combine(additionalDeviceDir, "modellist.json");
if (File.Exists(additionalModelListFile))
{
ReadModelList(additionalModelListFile, models);
}
}

CopyFilesRecursively(new DirectoryInfo(additionalDir), new DirectoryInfo(combinedDriverDir), true);
}
CMFile.DumpLighting(leDir, Path.Combine(dstDir, "lighting"));
CopyFilesRecursively(new DirectoryInfo(deviceDir), new DirectoryInfo(Path.Combine(dstDir, "device")));
CopyFilesRecursively(new DirectoryInfo(deviceDir), new DirectoryInfo(Path.Combine(dstDir, "device")), false);

CopyFilesRecursively(new DirectoryInfo(srcDir), new DirectoryInfo(combinedDriverDir), true);

// Combine modellist.json files
ReadModelList(modelListFile, models);
Expand Down Expand Up @@ -662,26 +674,29 @@ private static string CleanJson(string json)
return result.ToString();
}

private static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target)
private static void CopyFilesRecursively(DirectoryInfo source, DirectoryInfo target, bool all)
{
string[] extensions = { "json", "js" };
foreach (DirectoryInfo dir in source.GetDirectories())
{
// "res" folder contains some data we don't want
if (dir.Name != "res")
if (all || dir.Name != "res")
{
// Remove the special case folder (TODO: Make this more generic)
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name.Replace("(风控)", string.Empty)));
CopyFilesRecursively(dir, target.CreateSubdirectory(dir.Name.Replace("(风控)", string.Empty)), all);
}
}
foreach (FileInfo file in source.GetFiles())
{
if (extensions.Contains(file.Extension.ToLower().TrimStart(new char[] { '.' })))
if (all || extensions.Contains(file.Extension.ToLower().TrimStart(new char[] { '.' })))
{
file.CopyTo(Path.Combine(target.FullName, file.Name), true);
if (!file.Name.Contains("剑灵") && !file.Name.Contains("逆战"))
{
file.CopyTo(Path.Combine(target.FullName, file.Name), true);
}
}
}
if (target.GetFiles().Length == 0)
if (!all && target.GetFiles().Length == 0)
{
target.Delete();
}
Expand Down
10 changes: 8 additions & 2 deletions GK6X/WebGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ public static void Run()
}
if (server.IsRunning)
{
Process.Start(url);
//Process.Start("chrome", "--incognito " + url);
try
{
Process.Start(url);
//Process.Start("chrome", "--incognito " + url);
}
catch
{
}
}
}

Expand Down

0 comments on commit cdcd037

Please sign in to comment.