|
@@ -2,6 +2,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
+using System.IO.Compression;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
@@ -22,19 +23,32 @@ namespace Phihong_EVSE_UI_Tool
|
|
|
public partial class SaveSdCard : UserControl
|
|
|
{
|
|
|
private Properties.Settings mySettings = Properties.Settings.Default;
|
|
|
- private string sdFolderPath;
|
|
|
+ private string outputFolderPath;
|
|
|
+ private string settingModelName;
|
|
|
private List<string> toBeSavedFiles = new List<string>();
|
|
|
|
|
|
public SaveSdCard()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
- sdFolderPath = mySettings.SdCardPath;
|
|
|
- uxSdBrowseTextBox.Text = sdFolderPath;
|
|
|
+ outputFolderPath = mySettings.OutputFolderPath;
|
|
|
+ uxOutputDirectoryBrowseTextBox.Text = outputFolderPath;
|
|
|
+ uxModelNameTestBox.Text = mySettings.ModelName;
|
|
|
}
|
|
|
|
|
|
- private void SaveToSdCard()
|
|
|
+ private void SaveToDirectory()
|
|
|
{
|
|
|
+ if (Directory.Exists(Utility.ZIP_SOURCE_DIRECTORY))
|
|
|
+ {
|
|
|
+ Directory.Delete(Utility.ZIP_SOURCE_DIRECTORY, true);
|
|
|
+ }
|
|
|
+ if (Directory.Exists(Utility.ZIP_FILE_DIRECTORY))
|
|
|
+ {
|
|
|
+ Directory.Delete(Utility.ZIP_FILE_DIRECTORY, true);
|
|
|
+ }
|
|
|
+ Directory.CreateDirectory(Utility.ZIP_SOURCE_DIRECTORY);
|
|
|
+ Directory.CreateDirectory(Utility.ZIP_FILE_DIRECTORY);
|
|
|
+
|
|
|
if (uxSaveAllRadioButton.IsChecked.Value)
|
|
|
{
|
|
|
toBeSavedFiles = new List<string>(Utility.ChangedFiles.Keys);
|
|
@@ -46,35 +60,42 @@ namespace Phihong_EVSE_UI_Tool
|
|
|
select p.Key).ToList<string>();
|
|
|
}
|
|
|
|
|
|
- Directory.CreateDirectory(Path.Combine(sdFolderPath, Utility.SDCARD_SUBDIR));
|
|
|
-
|
|
|
foreach (string fileName in toBeSavedFiles)
|
|
|
{
|
|
|
File.Copy(Path.Combine(Utility.OUTPUT_DIRECTORY, fileName),
|
|
|
- Path.Combine(sdFolderPath, Utility.SDCARD_SUBDIR, fileName), true);
|
|
|
+ Path.Combine(Utility.ZIP_SOURCE_DIRECTORY, fileName), true);
|
|
|
}
|
|
|
|
|
|
foreach (string resName in Utility.REQ_FILELIST)
|
|
|
{
|
|
|
Uri srcPath = new Uri(Path.Combine(Utility.REQ_PARENTFOLDER, resName), UriKind.Relative);
|
|
|
- Utility.CopyFileFromResource(srcPath, Path.Combine(sdFolderPath, Utility.SDCARD_SUBDIR, resName));
|
|
|
+ Utility.CopyFileFromResource(srcPath, Path.Combine(Utility.ZIP_SOURCE_DIRECTORY, resName));
|
|
|
}
|
|
|
|
|
|
+ string modelName = uxModelNameTestBox.Text;
|
|
|
+ string zipFileName = string.Format("{0}_{1}.zip", modelName, DateTime.Now.ToString("yyyyMMddHHmmss"));
|
|
|
+ string temZipPath = Path.Combine(Utility.ZIP_FILE_DIRECTORY, Utility.TEMP_ZIP_FILE_NAME);
|
|
|
+ ZipFile.CreateFromDirectory(Utility.ZIP_SOURCE_DIRECTORY, temZipPath);
|
|
|
+
|
|
|
+ string tempHeaderBuildedZipPath = Path.Combine(Utility.ZIP_FILE_DIRECTORY, zipFileName);
|
|
|
+ FirmwareHeaderBuilder.AddFirmwareHeader(temZipPath, modelName, tempHeaderBuildedZipPath);
|
|
|
+ File.Copy(tempHeaderBuildedZipPath, Path.Combine(outputFolderPath, zipFileName));
|
|
|
+
|
|
|
switch (toBeSavedFiles.Count())
|
|
|
{
|
|
|
case 0:
|
|
|
- uxMessageTextBlock.Text = "Saved no image and 11 required files to SD card";
|
|
|
+ uxMessageTextBlock.Text = "Archived no image and 11 required files to File";
|
|
|
break;
|
|
|
case 1:
|
|
|
- uxMessageTextBlock.Text = "Saved 1 image and 11 required files to SD card";
|
|
|
+ uxMessageTextBlock.Text = "Archived 1 image and 11 required files to File";
|
|
|
break;
|
|
|
default:
|
|
|
- uxMessageTextBlock.Text = "Saved " + toBeSavedFiles.Count() + " images and 11 required files to SD card";
|
|
|
+ uxMessageTextBlock.Text = "Archived " + toBeSavedFiles.Count() + " images and 11 required files to File";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
System.Diagnostics.Process process = new System.Diagnostics.Process();
|
|
|
- process.StartInfo.FileName = Path.Combine(sdFolderPath, Utility.SDCARD_SUBDIR);
|
|
|
+ process.StartInfo.FileName = outputFolderPath;
|
|
|
process.Start();
|
|
|
}
|
|
|
|
|
@@ -92,31 +113,39 @@ namespace Phihong_EVSE_UI_Tool
|
|
|
var dlg = new CommonOpenFileDialog()
|
|
|
{
|
|
|
IsFolderPicker = true,
|
|
|
- Title = "Locate the SD card",
|
|
|
+ Title = "Locate the output directory",
|
|
|
};
|
|
|
if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
|
|
|
{
|
|
|
- sdFolderPath = dlg.FileName;
|
|
|
- uxSdBrowseTextBox.Text = sdFolderPath;
|
|
|
- mySettings.SdCardPath = sdFolderPath;
|
|
|
+ outputFolderPath = dlg.FileName;
|
|
|
+ uxOutputDirectoryBrowseTextBox.Text = outputFolderPath;
|
|
|
+ //mySettings.SdCardPath = sdFolderPath;
|
|
|
+ mySettings.OutputFolderPath = outputFolderPath;
|
|
|
mySettings.Save();
|
|
|
}
|
|
|
break;
|
|
|
case "Save":
|
|
|
- if(!Directory.Exists(sdFolderPath))
|
|
|
+
|
|
|
+ if (uxModelNameTestBox.Text.Length != 14)
|
|
|
{
|
|
|
- MessageBox.Show("Please locate the SD card path first",
|
|
|
+ MessageBox.Show("Model Name length shoud be 14",
|
|
|
+ "Invalid Model Name", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ mySettings.ModelName = uxModelNameTestBox.Text;
|
|
|
+ mySettings.Save();
|
|
|
+
|
|
|
+ if (!Directory.Exists(outputFolderPath))
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please locate the output directory first",
|
|
|
"Invalid Path", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
break;
|
|
|
}
|
|
|
- SaveToSdCard();
|
|
|
+ SaveToDirectory();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|