-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
353 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
<Platforms>AnyCPU;x64;x86;arm64</Platforms> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ini-parser-netcore" Version="3.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.ObjectModel; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace DefinitionMigrator | ||
{ | ||
internal class DefinitionParser | ||
{ | ||
public ReadOnlyCollection<string> DriverDirectories; | ||
public ReadOnlyCollection<string> AppDirectories; | ||
|
||
public DefinitionParser(string DefinitionFile) | ||
{ | ||
string content = File.ReadAllText(DefinitionFile); | ||
|
||
IniParser.IniDataParser parser = new(); | ||
parser.Configuration.ThrowExceptionsOnError = false; | ||
parser.Configuration.DuplicatePropertiesBehaviour = IniParser.Configuration.IniParserConfiguration.EDuplicatePropertiesBehaviour.AllowAndConcatenateValues; | ||
parser.Configuration.AllowDuplicateSections = true; | ||
parser.Configuration.AllowKeysWithoutSection = true; | ||
parser.Configuration.CaseInsensitive = false; | ||
parser.Configuration.SkipInvalidLines = true; | ||
IniParser.IniData data = parser.Parse(content); | ||
|
||
DriverDirectories = new ReadOnlyCollection<string>(data.Sections["Drivers"].Select(x => x.Key).ToList()); | ||
AppDirectories = new ReadOnlyCollection<string>(data.Sections["Apps"].Select(x => x.Key).ToList()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) The LumiaWOA and DuoWOA authors | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
using System; | ||
|
||
namespace DefinitionMigrator | ||
{ | ||
internal static class Logging | ||
{ | ||
public enum LoggingLevel | ||
{ | ||
Information, | ||
Warning, | ||
Error | ||
} | ||
|
||
private static readonly object lockObj = new(); | ||
|
||
public static void ShowProgress(long CurrentProgress, long TotalProgress, DateTime startTime, bool DisplayRed) | ||
{ | ||
DateTime now = DateTime.Now; | ||
TimeSpan timeSoFar = now - startTime; | ||
|
||
TimeSpan remaining = new(0); | ||
|
||
try | ||
{ | ||
remaining = TimeSpan.FromMilliseconds(timeSoFar.TotalMilliseconds / CurrentProgress * (TotalProgress - CurrentProgress)); | ||
} | ||
catch { } | ||
|
||
if (TotalProgress == 0) | ||
{ | ||
TotalProgress = 1; | ||
CurrentProgress = 1; | ||
} | ||
|
||
Log(string.Format("{0} {1:hh\\:mm\\:ss\\.f}", GetDismLikeProgBar((int)(CurrentProgress * 100 / TotalProgress)), remaining, remaining.TotalHours, remaining.Minutes, remaining.Seconds, remaining.Milliseconds), severity: DisplayRed ? LoggingLevel.Warning : LoggingLevel.Information, returnline: false); | ||
} | ||
|
||
private static string GetDismLikeProgBar(int perc) | ||
{ | ||
int eqsLength = (int)((double)perc / 100 * 55); | ||
string bases = new string('=', eqsLength) + new string(' ', 55 - eqsLength); | ||
bases = bases.Insert(28, perc + "%"); | ||
if (perc == 100) | ||
{ | ||
bases = bases[1..]; | ||
} | ||
else if (perc < 10) | ||
{ | ||
bases = bases.Insert(28, " "); | ||
} | ||
|
||
return "[" + bases + "]"; | ||
} | ||
|
||
public static void Log(string message, LoggingLevel severity = LoggingLevel.Information, bool returnline = true) | ||
{ | ||
lock (lockObj) | ||
{ | ||
if (message?.Length == 0) | ||
{ | ||
Console.WriteLine(); | ||
return; | ||
} | ||
|
||
ConsoleColor originalConsoleColor = Console.ForegroundColor; | ||
|
||
string msg = ""; | ||
|
||
switch (severity) | ||
{ | ||
case LoggingLevel.Warning: | ||
msg = " Warning "; | ||
Console.ForegroundColor = ConsoleColor.Yellow; | ||
break; | ||
case LoggingLevel.Error: | ||
msg = " Error "; | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
break; | ||
case LoggingLevel.Information: | ||
msg = "Information"; | ||
Console.ForegroundColor = originalConsoleColor; | ||
break; | ||
} | ||
|
||
if (returnline) | ||
{ | ||
Console.WriteLine(DateTime.Now.ToString("'['HH':'mm':'ss']'") + "[" + msg + "] " + message); | ||
} | ||
else | ||
{ | ||
Console.Write("\r" + DateTime.Now.ToString("'['HH':'mm':'ss']'") + "[" + msg + "] " + message); | ||
} | ||
|
||
Console.ForegroundColor = originalConsoleColor; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace DefinitionMigrator | ||
{ | ||
internal class Program | ||
{ | ||
private static void ConvertV1DefinitionsToV3(string dir) | ||
{ | ||
IEnumerable<string> definitions = Directory.EnumerateFiles($"{dir}\\definitions", "*.txt", SearchOption.AllDirectories).ToArray(); | ||
|
||
foreach (string definition in definitions) | ||
{ | ||
Logging.Log($"Processing {definition}"); | ||
string additionalFolder = "\\components\\ANYSOC\\Support\\Desktop\\SUPPORT.DESKTOP.POST_UPGRADE_ENABLEMENT"; | ||
IEnumerable<string> folders = File.ReadAllLines(definition).Where(x => !string.IsNullOrEmpty(x)).Select(x => dir + "\\" + x).Union(new string[] { dir + "\\" + additionalFolder }); | ||
|
||
IEnumerable<string> boundInfPackages = folders | ||
.SelectMany(x => Directory.EnumerateFiles(x, "*.inf", SearchOption.AllDirectories)) | ||
.Where(x => x.EndsWith(".inf", StringComparison.InvariantCultureIgnoreCase)) | ||
.Order(); | ||
|
||
List<string> xmlLines = [.. boundInfPackages.Select(inf => | ||
{ | ||
string path = Path.GetDirectoryName(inf); | ||
string name = Path.GetFileName(inf); | ||
string xmlLine = " <DriverPackageFile Path=\"$(mspackageroot)" + path.Replace(dir, "") + "\" Name=\"" + name + "\" ID=\"" + Path.GetFileNameWithoutExtension(inf) + "\"/>"; | ||
return xmlLine; | ||
}).Order()]; | ||
|
||
string start = "<FeatureManifest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://schemas.microsoft.com/embedded/2004/10/ImageUpdate\" Revision=\"1\" SchemaVersion=\"1.3\">\r\n <Drivers>\r\n <BaseDriverPackages>"; | ||
string end = " </BaseDriverPackages>\r\n </Drivers>\r\n</FeatureManifest>"; | ||
|
||
xmlLines.Insert(0, start); | ||
xmlLines.Add(end); | ||
|
||
File.WriteAllLines(definition.Replace(".txt", ".xml"), xmlLines); | ||
File.Delete(definition); | ||
} | ||
} | ||
|
||
private static void ConvertV2DefinitionsToV3(string dir) | ||
{ | ||
IEnumerable<string> definitions = Directory.EnumerateFiles($"{dir}\\definitions", "*.txt", SearchOption.AllDirectories).ToArray(); | ||
|
||
foreach (string definition in definitions) | ||
{ | ||
Logging.Log($"Processing {definition}"); | ||
DefinitionParser definitionParser = new(definition); | ||
IEnumerable<string> folders = definitionParser.DriverDirectories.Where(x => !string.IsNullOrEmpty(x)).Select(x => dir + "\\" + x); | ||
|
||
IEnumerable<string> boundInfPackages = folders | ||
.SelectMany(x => Directory.EnumerateFiles(x, "*.inf", SearchOption.AllDirectories)) | ||
.Where(x => x.EndsWith(".inf", StringComparison.InvariantCultureIgnoreCase)) | ||
.Order(); | ||
|
||
List<string> xmlLines = [.. boundInfPackages.Select(inf => | ||
{ | ||
string path = Path.GetDirectoryName(inf); | ||
string name = Path.GetFileName(inf); | ||
string xmlLine = " <DriverPackageFile Path=\"$(mspackageroot)" + path.Replace(dir, "") + "\" Name=\"" + name + "\" ID=\"" + Path.GetFileNameWithoutExtension(inf) + "\"/>"; | ||
return xmlLine; | ||
}).Order()]; | ||
|
||
List<string> deps = GetAppPackages(dir, definitionParser.AppDirectories); | ||
List<string> depXmlLines = [.. deps.Select(inf => | ||
{ | ||
string path = Path.GetDirectoryName(inf); | ||
string name = Path.GetFileName(inf); | ||
string xmlLine = " <PackageFile Path=\"$(mspackageroot)" + path.Replace(dir, "") + "\" Name=\"" + name + "\" ID=\"" + Path.GetFileNameWithoutExtension(inf) + "\"/>"; | ||
string licenseFile = Path.GetFileNameWithoutExtension(inf) + ".xml"; | ||
if (File.Exists(path + "\\" + licenseFile)) | ||
{ | ||
xmlLine = " <PackageFile Path=\"$(mspackageroot)" + path.Replace(dir, "") + "\" Name=\"" + name + "\" ID=\"" + Path.GetFileNameWithoutExtension(inf) + "\" LicenseFile=\"" + licenseFile + "\"/>"; | ||
} | ||
return xmlLine; | ||
}).Order()]; | ||
|
||
string start = "<FeatureManifest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://schemas.microsoft.com/embedded/2004/10/ImageUpdate\" Revision=\"1\" SchemaVersion=\"1.3\">\r\n <Drivers>\r\n <BaseDriverPackages>"; | ||
string mid = " </BaseDriverPackages>\r\n </Drivers>\r\n <AppX>\r\n <AppXPackages>"; | ||
string end = " </AppXPackages>\r\n </AppX>\r\n</FeatureManifest>"; | ||
|
||
xmlLines.Insert(0, start); | ||
xmlLines.Add(mid); | ||
xmlLines.AddRange(depXmlLines); | ||
xmlLines.Add(end); | ||
|
||
File.WriteAllLines(definition.Replace(".txt", ".xml"), xmlLines); | ||
File.Delete(definition); | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
ConvertV2DefinitionsToV3("C:\\Users\\Gus\\Documents\\GitHub\\SurfaceDuo-Drivers"); | ||
} | ||
|
||
private static List<string> GetAppPackages(string DriverRepo, ReadOnlyCollection<string> appPaths) | ||
{ | ||
List<string> deps = []; | ||
|
||
foreach (string path in appPaths) | ||
{ | ||
IEnumerable<string> appxs = Directory.EnumerateFiles($"{DriverRepo}\\{path}", "*.appx", SearchOption.AllDirectories) | ||
.Where(x => x.EndsWith(".appx", StringComparison.InvariantCultureIgnoreCase)); | ||
IEnumerable<string> msixs = Directory.EnumerateFiles($"{DriverRepo}\\{path}", "*.msix", SearchOption.AllDirectories) | ||
.Where(x => x.EndsWith(".msix", StringComparison.InvariantCultureIgnoreCase)); | ||
IEnumerable<string> appxbundles = Directory.EnumerateFiles($"{DriverRepo}\\{path}", "*.appxbundle", SearchOption.AllDirectories) | ||
.Where(x => x.EndsWith(".appxbundle", StringComparison.InvariantCultureIgnoreCase)); | ||
IEnumerable<string> msixbundles = Directory.EnumerateFiles($"{DriverRepo}\\{path}", "*.msixbundle", SearchOption.AllDirectories) | ||
.Where(x => x.EndsWith(".msixbundle", StringComparison.InvariantCultureIgnoreCase)); | ||
|
||
deps.AddRange(appxs); | ||
deps.AddRange(msixs); | ||
deps.AddRange(appxbundles); | ||
deps.AddRange(msixbundles); | ||
} | ||
|
||
return deps; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<assemblyIdentity version="1.0.0.3" name="MyApplication.app"/> | ||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> | ||
<security> | ||
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"> | ||
<requestedExecutionLevel level="highestAvailable" uiAccess="false" /> | ||
</requestedPrivileges> | ||
</security> | ||
</trustInfo> | ||
|
||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> | ||
<application> | ||
<!-- Windows 10 --> | ||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> | ||
</application> | ||
</compatibility> | ||
|
||
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) --> | ||
<dependency> | ||
<dependentAssembly> | ||
<assemblyIdentity | ||
type="win32" | ||
name="Microsoft.Windows.Common-Controls" | ||
version="6.0.0.0" | ||
processorArchitecture="*" | ||
publicKeyToken="6595b64144ccf1df" | ||
language="*" | ||
/> | ||
</dependentAssembly> | ||
</dependency> | ||
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.