123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace Phihong_EVSE_UI_Tool
- {
- public static class Utility
- {
- public const string BG_PARENTFOLDER = "Background";
- public const string BG_INITIAL = "0_init.bmp";
- public const string BG_IDLE = "1_idle.bmp";
- public const string BG_VERIFY = "2_verify.bmp";
- public const string BG_VERIFYOK = "3_carChkok.bmp";
- public const string BG_VERIFYFAIL = "4_chkfail.bmp";
- public const string BG_PLUG = "5_plug.bmp";
- public const string BG_PRECHARGE = "6_precharge.bmp";
- public const string BG_CHARGING = "7_charging.bmp";
- public const string BG_COMPLETE = "8_complete.bmp";
- public const string BG_MAINTAIN = "9_fix.bmp";
- public const string BG_EMERGENCY = "10_emc.bmp";
- public const string ICO_PARENTFOLDER = "ICO";
- public const string ICO_NAME = "60.ICO";
- public const string ICO_MAINLOGO = "10.bmp";
- public const string ICO_MAINLOGO_HIDE = "10_hide.bmp";
- public const string ICO_COMPLETELOGO = "62.bmp";
- public const string ICO_COMPLETELOGO_HIDE = "62_hide.bmp";
- public const string ICO_URL = "66.bmp";
- public const string ICO_URL_HIDE = "66_hide.bmp";
- public const string TEMP_ZIP_FILE_NAME = @"tmp.zip";
- public const string REQ_PARENTFOLDER = "Required";
- public static List<string> REQ_FILELIST = new List<string>()
- {
- "0_DWIN_ASC.HZK", "12_HZK.BIN", "13.bin", "14.bin", "22_Config.bin",
- "24_Unicode_Roboto_18_22.dzk", "26_Unicode_Roboto_36_44.dzk", "28_Unicode_Roboto_28_56.dzk",
- "30_Unicode_Roboto_14_28.dzk", "32_Unicode_Roboto_28_56.dzk", "CONFIG.txt"
- };
- //public const string SDCARD_SUBDIR = "DWIN_SET";
- public static readonly string OUTPUT_DIRECTORY = Environment.CurrentDirectory + @"\Output";
- public static readonly string CUSTOM_DIRECTORY = Environment.CurrentDirectory + @"\CustomTemp";
- public static readonly string ZIP_SOURCE_DIRECTORY = Environment.CurrentDirectory + @"\DWIN_SET";
- public static readonly string ZIP_FILE_DIRECTORY = Environment.CurrentDirectory + @"\ZipFile";
- public static Dictionary<string, bool> ChangedFiles = new Dictionary<string, bool>()
- {
- {BG_INITIAL, false}, {BG_IDLE, false}, {BG_VERIFY, false},
- {BG_VERIFYOK, false}, {BG_VERIFYFAIL, false}, {BG_PLUG, false},
- {BG_PRECHARGE, false}, {BG_CHARGING, false}, {BG_COMPLETE, false},
- {BG_MAINTAIN, false}, {BG_EMERGENCY, false}, {ICO_NAME, false}
- };
- public static void CopyFileFromResource(Uri uriString, string destPath)
- {
- using (var resource = Application.GetResourceStream(uriString).Stream)
- {
- using (var file = new FileStream(destPath, FileMode.Create, FileAccess.Write))
- {
- resource.CopyTo(file);
- }
- }
- }
- public static void LoadImageFromPath(Image imgControl, string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- imgControl.BeginInit();
- imgControl.Source = bitmap;
- imgControl.EndInit();
- }
- public static bool IsBackgroundImageSizeQualified(string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- if (bitmap.PixelWidth != 800 || bitmap.PixelHeight != 480)
- {
- return false;
- }
- return true;
- }
- public static bool IsIcoImageSizeQualified(string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- if (bitmap.PixelWidth > 255 || bitmap.PixelHeight > 255)
- {
- return false;
- }
- return true;
- }
- public static bool IsIcoLogoSizeQualified(string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- if (bitmap.PixelWidth != 255 || bitmap.PixelHeight != 34)
- {
- return false;
- }
- return true;
- }
- public static bool IsIcoUrlSizeQualified(string path)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- if (bitmap.PixelWidth != 233 || bitmap.PixelHeight != 28)
- {
- return false;
- }
- return true;
- }
- public static void ConvertFileToBitmap565Array(string path, out int width, out int height, out byte[] pixels)
- {
- FileStream fstream = new FileStream(path, FileMode.Open);
- ConvertToBitmap565(out width, out height, out pixels, fstream);
- }
- public static void ConvertResourceToBitmap565Array(Uri uriString, out int width, out int height, out byte[] pixels)
- {
- using (var resource = Application.GetResourceStream(uriString).Stream)
- {
- ConvertToBitmap565(out width, out height, out pixels, resource);
- }
- }
- private static void ConvertToBitmap565(out int width, out int height, out byte[] pixels, Stream fstream)
- {
- BitmapImage bitmap = new BitmapImage();
- bitmap.BeginInit();
- bitmap.StreamSource = fstream;
- bitmap.CacheOption = BitmapCacheOption.OnLoad;
- bitmap.EndInit();
- fstream.Close();
- FormatConvertedBitmap newFormated = new FormatConvertedBitmap();
- newFormated.BeginInit();
- newFormated.Source = bitmap;
- newFormated.DestinationFormat = PixelFormats.Bgr565;
- newFormated.EndInit();
- width = newFormated.PixelWidth;
- height = newFormated.PixelHeight;
- var stride = (newFormated.PixelWidth * newFormated.Format.BitsPerPixel + 7) / 8;
- pixels = new byte[newFormated.PixelHeight * stride];
- newFormated.CopyPixels(pixels, stride, 0);
- for (int i = 0; i < pixels.Length; i += 2)
- {
- byte temp = pixels[i];
- pixels[i] = pixels[i + 1];
- pixels[i + 1] = temp;
- }
- }
- }
- }
|