123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using Microsoft.WindowsAPICodePack.Dialogs;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- namespace Phihong_EVSE_UI_Tool
- {
- /// <summary>
- /// SaveSdCard.xaml 的互動邏輯
- /// </summary>
- public partial class SaveSdCard : UserControl
- {
- private Properties.Settings mySettings = Properties.Settings.Default;
- private string sdFolderPath;
- private List<string> toBeSavedFiles = new List<string>();
- public SaveSdCard()
- {
- InitializeComponent();
- sdFolderPath = mySettings.SdCardPath;
- uxSdBrowseTextBox.Text = sdFolderPath;
- }
- private void SaveToSdCard()
- {
- if (uxSaveAllRadioButton.IsChecked.Value)
- {
- toBeSavedFiles = new List<string>(Utility.ChangedFiles.Keys);
- }
- else
- {
- toBeSavedFiles = (from p in Utility.ChangedFiles
- where p.Value
- 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);
- }
- switch (toBeSavedFiles.Count())
- {
- case 0:
- uxMessageTextBlock.Text = "Saved no file";
- break;
- case 1:
- uxMessageTextBlock.Text = "Saved 1 file to SD card";
- break;
- default:
- uxMessageTextBlock.Text = "Saved " + toBeSavedFiles.Count() + " files to SD card";
- break;
- }
- System.Diagnostics.Process process = new System.Diagnostics.Process();
- process.StartInfo.FileName = Path.Combine(sdFolderPath, Utility.SDCARD_SUBDIR);
- process.Start();
- }
- private void uxBrowseButton_Click(object sender, RoutedEventArgs e)
- {
- Button btn = e.Source as Button;
- if (btn is null)
- {
- return;
- }
- switch (btn.Tag.ToString())
- {
- case "Browse":
- var dlg = new CommonOpenFileDialog()
- {
- IsFolderPicker = true,
- Title = "Locate the SD card",
- };
- if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
- {
- sdFolderPath = dlg.FileName;
- uxSdBrowseTextBox.Text = sdFolderPath;
- mySettings.SdCardPath = sdFolderPath;
- mySettings.Save();
- }
- break;
- case "Save":
- if(!Directory.Exists(sdFolderPath))
- {
- MessageBox.Show("Please locate the SD card path first",
- "Invalid Path", MessageBoxButton.OK, MessageBoxImage.Error);
- break;
- }
- SaveToSdCard();
- break;
- default:
- break;
- }
-
- }
- }
- }
|