Initial commit: application ColorPicker (palette, pipette ecran, couleur de dossier)
This commit is contained in:
34
tests/IconPreview.cs
Normal file
34
tests/IconPreview.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace ColorPickerApp
|
||||
{
|
||||
internal static class IconPreview
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
string dir = Path.Combine(Path.GetTempPath(), "cp_preview");
|
||||
Directory.CreateDirectory(dir);
|
||||
FolderColorizer.ApplyColor(dir, Color.FromArgb(220, 40, 60));
|
||||
|
||||
byte[] icoBytes = File.ReadAllBytes(Path.Combine(dir, ".colorpicker_folder.ico"));
|
||||
int count = System.BitConverter.ToUInt16(icoBytes, 4);
|
||||
// trouver l'entree 256x256 (largeur stockee = 0) avec le plus grand bytesInRes
|
||||
int bestOffset = -1, bestSize = -1, bestLen = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int entryOffset = 6 + i * 16;
|
||||
int w = icoBytes[entryOffset];
|
||||
int len = System.BitConverter.ToInt32(icoBytes, entryOffset + 8);
|
||||
int off = System.BitConverter.ToInt32(icoBytes, entryOffset + 12);
|
||||
if (w == 0 && len > bestLen) { bestLen = len; bestOffset = off; bestSize = w; }
|
||||
}
|
||||
var pngBytes = new byte[bestLen];
|
||||
System.Array.Copy(icoBytes, bestOffset, pngBytes, 0, bestLen);
|
||||
File.WriteAllBytes(Path.Combine(Path.GetTempPath(), "cp_icon_preview.png"), pngBytes);
|
||||
|
||||
FolderColorizer.RestoreDefault(dir);
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
tests/TestHarness.cs
Normal file
46
tests/TestHarness.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
namespace ColorPickerApp
|
||||
{
|
||||
internal static class TestHarness
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
string testDir = Path.Combine(Path.GetTempPath(), "cp_test_" + Guid.NewGuid().ToString("N").Substring(0, 8));
|
||||
Directory.CreateDirectory(testDir);
|
||||
Console.WriteLine("Dossier de test: " + testDir);
|
||||
|
||||
FolderColorizer.ApplyColor(testDir, Color.FromArgb(220, 40, 60));
|
||||
Console.WriteLine("Apres ApplyColor:");
|
||||
foreach (var f in Directory.GetFiles(testDir, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
Console.WriteLine(" " + f + " attrs=" + File.GetAttributes(f));
|
||||
}
|
||||
Console.WriteLine(" dossier attrs=" + new DirectoryInfo(testDir).Attributes);
|
||||
Console.WriteLine(" HasCustomColor=" + FolderColorizer.HasCustomColor(testDir));
|
||||
|
||||
string iniPath = Path.Combine(testDir, "desktop.ini");
|
||||
Console.WriteLine("--- desktop.ini ---");
|
||||
Console.WriteLine(File.ReadAllText(iniPath));
|
||||
|
||||
string icoPath = Path.Combine(testDir, ".colorpicker_folder.ico");
|
||||
var icoBytes = File.ReadAllBytes(icoPath);
|
||||
Console.WriteLine("Taille .ico: " + icoBytes.Length + " octets, count entries=" + BitConverter.ToUInt16(icoBytes, 4));
|
||||
|
||||
FolderColorizer.RestoreDefault(testDir);
|
||||
Console.WriteLine("Apres RestoreDefault:");
|
||||
foreach (var f in Directory.GetFiles(testDir, "*", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
Console.WriteLine(" " + f);
|
||||
}
|
||||
Console.WriteLine(" dossier attrs=" + new DirectoryInfo(testDir).Attributes);
|
||||
Console.WriteLine(" HasCustomColor=" + FolderColorizer.HasCustomColor(testDir));
|
||||
Console.WriteLine("Fichiers restants: " + Directory.GetFiles(testDir).Length);
|
||||
|
||||
Directory.Delete(testDir, true);
|
||||
Console.WriteLine("OK - test termine sans exception.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user