Skip to content

Commit

Permalink
add auto update, add LG expert actions and auto set current device
Browse files Browse the repository at this point in the history
  • Loading branch information
Maassoft committed Dec 4, 2022
1 parent cb09d5c commit 43f038e
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 127 deletions.
4 changes: 2 additions & 2 deletions ColorControl/ColorControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<PublisherName>Maassoft</PublisherName>
<Company>Maassoft</Company>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>8.1.0.0</ApplicationVersion>
<Version>8.1.0.0</Version>
<ApplicationVersion>8.2.0.0</ApplicationVersion>
<Version>8.2.0.0</Version>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>false</BootstrapperEnabled>
Expand Down
102 changes: 101 additions & 1 deletion ColorControl/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
using System.Drawing;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Principal;
using System.ServiceProcess;
using System.Text;
Expand All @@ -25,6 +27,7 @@
using System.Windows.Forms;
using Windows.Devices.Enumeration;
using Windows.Devices.Enumeration.Pnp;
using Task = System.Threading.Tasks.Task;

namespace ColorControl.Common
{
Expand Down Expand Up @@ -52,7 +55,7 @@ public enum ModKeys : int
private static bool WinKeyDown = false;
private static Keys[] KeysWithoutModifiers = new[] { Keys.F13, Keys.F14, Keys.F15, Keys.F16, Keys.F17, Keys.F18, Keys.F19, Keys.F20, Keys.F21, Keys.F22, Keys.F23, Keys.F24 };

private static string SERVICE_NAME = "Color Control Service";
public static string SERVICE_NAME = "Color Control Service";

public static string ELEVATION_MSG = @"Elevation is needed in some cases where ColorControl needs administrator rights.
Some operations like installing a service, changing the priority of a process or creating a temporary IP-route for improved WOL-functionality will not work without those rights.
Expand Down Expand Up @@ -1138,5 +1141,102 @@ public static string Base64Decode(string base64EncodedData)
var base64EncodedBytes = Convert.FromBase64String(base64EncodedData);
return Encoding.UTF8.GetString(base64EncodedBytes);
}

public static async Task DownloadFileAsync(string url, string filePath)
{
var httpClient = new HttpClient();
using var stream = await httpClient.GetStreamAsync(url);

using var fileStream = new FileStream(filePath, FileMode.OpenOrCreate);

await stream.CopyToAsync(fileStream);
}

public static void UnZipFile(string zipFile, string filePath)
{
ZipFile.ExtractToDirectory(zipFile, filePath);
}

public static void UpdateFiles(string clientPath, string updatePath)
{
var infos = new List<FileSystemInfo>();

GetFileSystemInfos(updatePath, infos);

foreach (var info in infos)
{
var subPath = info.FullName.Replace(updatePath, "");

if (subPath[0] == '\\')
{
subPath = subPath.Substring(1);
}

var targetPath = Path.Combine(clientPath, subPath);

//Logger.Debug($"Path: {updatePath}, info: {info.FullName}, target: {targetPath}");

if (info is DirectoryInfo)
{
if (!Directory.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}

continue;
}

var fileInfo = info as FileInfo;

var oldPath = targetPath + ".old";

if (File.Exists(oldPath))
{
File.Delete(oldPath);
}

if (File.Exists(targetPath))
{
if (CompareFiles(fileInfo.FullName, targetPath))
{
continue;
}

File.Move(targetPath, targetPath + ".old");
}

fileInfo.CopyTo(targetPath);
}
}

public static void GetFileSystemInfos(string path, List<FileSystemInfo> infos)
{
var directory = new DirectoryInfo(path);

foreach (var dir in directory.GetDirectories())
{
infos.Add(dir);
GetFileSystemInfos(dir.FullName, infos);
}

foreach (var file in directory.GetFiles())
{
infos.Add(file);
}
}

public static string SHA256CheckSum(string filePath)
{
using (SHA256 SHA256 = SHA256.Create())
{
using (FileStream fileStream = File.OpenRead(filePath))
return Convert.ToBase64String(SHA256.ComputeHash(fileStream));
}
}

public static bool CompareFiles(string filePath1, string filePath2)
{
return SHA256CheckSum(filePath1) == SHA256CheckSum(filePath2);
}
}
}
1 change: 1 addition & 0 deletions ColorControl/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Config
public bool MinimizeOnClose { get; set; }
public bool MinimizeToTray { get; set; }
public bool CheckForUpdates { get; set; }
public bool AutoInstallUpdates { get; set; }
public int DisplaySettingsDelay { get; set; }
public string ScreenSaverShortcut { get; set; }
public int FormWidth { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion ColorControl/Forms/FormUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static ToolStripMenuItem BuildDropDownMenuEx(ToolStripItemCollection item
else
{
range = new List<int>();
for (var i = 0; i <= 10; i++)
for (var i = min < 0 ? -10 : 0; i <= 10; i++)
{
range.Add(i * (max / 10));
}
Expand Down
Loading

0 comments on commit 43f038e

Please sign in to comment.