Skip to content

Commit

Permalink
refactor and optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
PHAN Xuan Quang committed Nov 4, 2024
1 parent c7d3b8f commit a0253dc
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PackageTags>Neo 2.0.0</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<Target Name="RemoveFoldersWithMuiFiles" AfterTargets="Build">
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Adobe Camera Profiles Unlocker Neo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<Button x:Name="ResetButton" Content="Reset" Width="100" Click="ResetButton_Click"/>
</StackPanel>

<controls:DataGrid BorderBrush="{StaticResource AccentAAFillColorDisabled}" BorderThickness="1" x:Name="ProfileTable" AutoGenerateColumns="False" IsReadOnly="True" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" Margin="0,20,0,10">
<controls:DataGrid BorderBrush="{StaticResource AccentAAFillColorDisabled}" BorderThickness="1" x:Name="ProfileTable" AutoGenerateColumns="False" IsReadOnly="True" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserSortColumns="False" Margin="0,20,0,10" MaxHeight="500">
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="No." Binding="{Binding No}" Width="70" />
<controls:DataGridTextColumn Header="Camera Model" Binding="{Binding ProfileName}" Width="*" />
Expand Down
324 changes: 129 additions & 195 deletions Adobe Camera Profiles Unlocker Neo/MainWindow.xaml.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Engineer/Updater.cs → Engineer/AppUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Engineer
{
public static class Updater
public static class AppUpdater
{
public static async Task<Release?> GetGithubLatestReleaseInfo()
{
Expand Down
10 changes: 0 additions & 10 deletions Engineer/CameraRaw.cs

This file was deleted.

17 changes: 9 additions & 8 deletions Engineer/FileUpdater.cs → Engineer/ContentModifier.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
namespace Engineer
{
public static class FileUpdater
public static class ContentModifier
{
public static void ModifyXMPContent(string xmlPath, string brand, string outputCameraModel)
private static readonly string AuthorCredit = "© 2024 Phan Xuan Quang / Github: @phanxuanquang";
public static void ModifyXmp(string xmlPath, string outputCameraModel)
{
var lines = File.ReadAllLines(xmlPath);

Parallel.For(0, lines.Length, i =>
{
if (lines[i].Contains("crs:Copyright="))
{
lines[i] = "crs:Copyright=\"© 2024 Phan Xuan Quang / Github: @phanxuanquang\"";
lines[i] = $"crs:Copyright=\"{AuthorCredit}\"";
}

if (lines[i].Contains("crs:CameraModelRestriction="))
{
lines[i] = $"crs:CameraModelRestriction=\"{outputCameraModel}\"";
lines[i] = $"crs:CameraModelRestriction=\"{outputCameraModel.Trim()}\"";
}

if (lines[i].Contains("crs:CameraProfile="))
Expand All @@ -27,20 +28,20 @@ public static void ModifyXMPContent(string xmlPath, string brand, string outputC
File.WriteAllLines(xmlPath, lines);
}

public static void ModifyXMLContent(string xmlPath, string brand, string outputCameraModel)
public static void ModifyXml(string xmlPath, string cameraModel, string outputCameraModel)
{
var lines = File.ReadAllLines(xmlPath);

Parallel.For(0, lines.Length, i =>
{
if (lines[i].Contains("<ProfileName>"))
{
lines[i] = lines[i].Replace("Camera", $"{brand}:");
lines[i] = lines[i].Replace("Camera", $"{cameraModel.Trim()}:");
}

if (lines[i].Contains("Copyright"))
{
lines[i] = lines[i].Replace(lines[i], "<Copyright>© 2024 Phan Xuan Quang / Github: @phanxuanquang</Copyright>");
lines[i] = lines[i].Replace(lines[i], $"<Copyright>{AuthorCredit}</Copyright>");
}

if (lines[i].Contains("<ProfileCalibrationSignature>"))
Expand All @@ -50,7 +51,7 @@ public static void ModifyXMLContent(string xmlPath, string brand, string outputC

if (lines[i].Contains("<UniqueCameraModelRestriction>"))
{
lines[i] = lines[i].Replace(lines[i], $"<UniqueCameraModelRestriction>{outputCameraModel}</UniqueCameraModelRestriction>");
lines[i] = lines[i].Replace(lines[i], $"<UniqueCameraModelRestriction>{outputCameraModel.Trim()}</UniqueCameraModelRestriction>");
}
});

Expand Down
22 changes: 14 additions & 8 deletions Engineer/DcpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ namespace Engineer
{
public static class DcpHelper
{
private static readonly string DcpToolPath = @"Assets\dcpTool.exe";

public static string AsXML(string dcpPath)
{
var xmlPath = $"{AppDomain.CurrentDomain.BaseDirectory}\\{Path.GetFileName(dcpPath).Replace(".dcp", ".xml")}";

var exeInfor = new ProcessStartInfo();
exeInfor.FileName = @"Assets\dcpTool.exe";
exeInfor.CreateNoWindow = true;
exeInfor.Arguments = $"-d \"{dcpPath}\" \"{xmlPath}\"";
var exeInfor = new ProcessStartInfo
{
FileName = DcpToolPath,
CreateNoWindow = true,
Arguments = $"-d \"{dcpPath}\" \"{xmlPath}\""
};

var executer = Process.Start(exeInfor);
executer.WaitForExit();
Expand All @@ -21,10 +25,12 @@ public static string AsXML(string dcpPath)

public static void AsDCP(string xmlPath, string dcpPath)
{
var exeInfor = new ProcessStartInfo();
exeInfor.FileName = @"Assets\dcpTool.exe";
exeInfor.Arguments = $"-c \"{xmlPath}\" \"{dcpPath}.dcp\"";
exeInfor.CreateNoWindow = true;
var exeInfor = new ProcessStartInfo
{
FileName = DcpToolPath,
Arguments = $"-c \"{xmlPath}\" \"{dcpPath}.dcp\"",
CreateNoWindow = true
};

var executer = Process.Start(exeInfor);
executer.WaitForExit();
Expand Down
38 changes: 32 additions & 6 deletions Engineer/DirectoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,29 @@ namespace Engineer
{
public static class DirectoryHelper
{
public static List<string> GetProfileFiles(string folderPath)
public static async Task<List<string>> GetProfiles(string folderPath)
{
var dcpFiles = Directory.GetFiles(folderPath, "*.dcp").ToList();
var xmpFiles = Directory.GetFiles(folderPath, "*.xmp").ToList();
return dcpFiles.Concat(xmpFiles).ToList();
var profiles = new ConcurrentBag<string>();

await Task.WhenAll(
Task.Run(() => Parallel.ForEach(Directory.EnumerateFiles(folderPath, "*.dcp"), file =>
{
profiles.Add(file);
})),
Task.Run(() => Parallel.ForEach(Directory.EnumerateFiles(folderPath, "*.xmp"), file =>
{
profiles.Add(file);
}))
);

return new List<string>(profiles);
}

public static async Task<List<string>> GetFolders(string path, bool getDirectChildrenOnly = true)
{
if (!Directory.EnumerateFileSystemEntries(path).GetEnumerator().MoveNext())
{
return new List<string>();
return [];
}

if (getDirectChildrenOnly)
Expand All @@ -33,15 +45,29 @@ public static async Task<List<string>> GetFolders(string path, bool getDirectChi
{
var subfolders = await Task.Run(() => Directory.GetDirectories(currentPath));

await Parallel.ForEachAsync(subfolders, async (folder, cancellationToken) =>
await Parallel.ForEachAsync(subfolders, (folder, cancellationToken) =>
{
folders.Add(folder);
stack.Push(folder);
return new ValueTask();
});
}
}

return new List<string>(folders);
}

public static bool IsDirectoryExist(string path)
{
return Directory.Exists(path);
}

public static void CreateDirectoryIfNotExist(string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Engineer
namespace Engineer.Models
{
public class CameraProfile
{
Expand Down
11 changes: 11 additions & 0 deletions Engineer/Models/DirectoryConstant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Engineer.Models
{
public class DirectoryConstant
{
public const string CameraRawRootDir = @"C:\ProgramData\Adobe\CameraRaw";
public const string AdobeStandardProfilesDir = @"C:\ProgramData\Adobe\CameraRaw\CameraProfiles\Adobe Standard";
public const string VariantProfileFoldersDir = @"C:\ProgramData\Adobe\CameraRaw\CameraProfiles\Camera";
public const string VariantProfileFoldersDirAlt = @"C:\ProgramData\Adobe\CameraRaw\Settings\Adobe\Profiles\Camera";
public const string CameraRaw3rdPartyProfilesDir = @"C:\ProgramData\Adobe\CameraRaw\CameraProfiles";
}
}
4 changes: 2 additions & 2 deletions Engineer/GeneralHelper.cs → Engineer/WindowsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

namespace Engineer
{
public static class GeneralHelper
public static class WindowsHelper
{
public static bool IsUserAdmin()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
WindowsPrincipal principal = new(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}

Expand Down

0 comments on commit a0253dc

Please sign in to comment.