private void saveAsAppZipPackagePath_Click(object sender, RoutedEventArgs e) { OpenDialogView openFolderDialog = new OpenDialogView(); OpenDialogViewModel folderDialogView = (OpenDialogViewModel)openFolderDialog.DataContext; folderDialogView.Caption = "Select Path for Saving .appPckZip Package"; folderDialogView.SaveText = "Save"; folderDialogView.FileNameText = "Name(.appPckZip):"; folderDialogView.FileFilterText = "Type(.appPckZip):"; folderDialogView.FileFilterExtensions.Clear(); folderDialogView.FileFilterExtensions.Add(".appPckZip"); folderDialogView.SelectedFileFilterExtension = ".appPckZip"; folderDialogView.IsSaveDialog = true; OpenDialogViewModelEx.addDesktop(folderDialogView); if (folderDialogView.Show() == true) { if (folderDialogView.SelectedFolder is object) { string path = pathConverter.convertInvalidFolderName(folderDialogView.SelectedFolder.Path); string name = pathConverter.convertInvalidFileName(folderDialogView.SelectedFilePath == null ? string.Empty : folderDialogView.SelectedFilePath).TrimStart(); if (System.IO.Directory.Exists(path) && name.Length > 0) { saveZipName.Text = System.IO.Path.Combine(path, name + ".appPckZip"); } } } }
private void selectAppResource_Click(object sender, RoutedEventArgs e) { OpenDialogView openFolderDialog = new OpenDialogView(); OpenDialogViewModel folderDialogView = (OpenDialogViewModel)openFolderDialog.DataContext; folderDialogView.Caption = "Select a Resource Folder"; folderDialogView.OpenText = "Select"; folderDialogView.FileNameText = "Folder:"; folderDialogView.FileFilterText = "Local:"; folderDialogView.IsDirectoryChooser = true; if (folderDialogView.Show() == true) { string path = folderDialogView.SelectedFilePath; if (path != null) { if (System.IO.Directory.Exists(path)) { OpenDialogView openDialog = new OpenDialogView(); OpenDialogViewModel dialogView = (OpenDialogViewModel)openDialog.DataContext; #region 择为前一步所选的文件夹 string showName; if (System.IO.Path.GetPathRoot(path) == path) { showName = path; } else { showName = path.Substring(path.LastIndexOf(@"\") + 1); } dialogView.Items.Clear(); OpenDialogViewModelEx.addPathOpenDialog(dialogView, path, showName, "\\Icons\\folder.ico", "\\Icons\\folder.ico", true); dialogView.Caption = "Select a Executable File From Resource Folder"; dialogView.OpenText = "Select"; #endregion if (dialogView.Show() == true) { string file = dialogView.SelectedFilePath; if (file != null) { if (System.IO.File.Exists(file)) { folderName.Text = path; fileName.Text = file; } } } } } } }
private void selectFile_Click(object sender, RoutedEventArgs e) { OpenDialogView openDialog = new OpenDialogView(); OpenDialogViewModel dialogView = (OpenDialogViewModel)openDialog.DataContext; OpenDialogViewModelEx.addDesktop(dialogView); dialogView.Caption = "Select a File"; dialogView.OpenText = "Select"; if (dialogView.Show() == true) { string path = dialogView.SelectedFilePath; if (path != null) { if (System.IO.File.Exists(path)) { fileName.Text = path; } } } }
private void loadAppZipPackagePath_Click(object sender, RoutedEventArgs e) { OpenDialogView openDialog = new OpenDialogView(); OpenDialogViewModel dialogView = (OpenDialogViewModel)openDialog.DataContext; OpenDialogViewModelEx.addDesktop(dialogView); dialogView.Caption = "Select a .appPckZip Package"; dialogView.FileFilterExtensions.Clear(); dialogView.FileFilterExtensions.Add(".appPckZip"); dialogView.SelectedFileFilterExtension = ".appPckZip"; if (dialogView.Show() == true) { string path = dialogView.SelectedFilePath; if (path != null) { if (System.IO.File.Exists(path)) { loadZipName.Text = path; } } } }
private void LoadFromappZip_Click(object sender, RoutedEventArgs e) { if (getAppsModel.Count <= 0) { var result = this.ShowModalInputExternal("Note", "Add at least one new AppsGroup first."); if (result == null) { return; } AppGroup newItem = new AppGroup() { AppGroupName = result, appItems = new ObservableCollection <AppItem>() }; getAppsModel.Add(newItem); appTabControl.SelectedIndex = 0; } //选择.appZip包 OpenDialogView openDialog = new OpenDialogView(); OpenDialogViewModel dialogView = (OpenDialogViewModel)openDialog.DataContext; OpenDialogViewModelEx.addDesktop(dialogView); dialogView.Caption = "Select a .appZip Package"; dialogView.FileFilterExtensions.Clear(); dialogView.FileFilterExtensions.Add(".appZip"); dialogView.SelectedFileFilterExtension = ".appZip"; if (dialogView.Show() == true) { string path = dialogView.SelectedFilePath; if (path != null) { if (System.IO.File.Exists(path)) { //开始解压.appZip // ^AppZipPackage_{\w{8}-(\w{4}-){3}\w{12}}.log$ 此为正则表达式匹配log日志 processBar.showRingBar(this, () => { try { string guid = Guid.NewGuid().ToString("B"); string appMainFolder = System.AppDomain.CurrentDomain.BaseDirectory; string logFile = string.Empty; string appName = string.Empty; string appDescription = string.Empty; string appRelativePath = string.Empty; //可执行文件,相对路径相对appZipPath string appZipPath = "APPsData\\" + guid; //项目下文件夹,如果存在则新建GUID文件夹,作为APP的容器文件夹 string appAbsolutePath = pathConverter.getAbsolutePath(appZipPath, appMainFolder); if (Directory.Exists(appAbsolutePath)) { do { guid = Guid.NewGuid().ToString("B"); appZipPath = "APPsData\\" + guid; appAbsolutePath = pathConverter.getAbsolutePath(appZipPath, appMainFolder); }while (!Directory.Exists(appAbsolutePath)); } sharpZipHelper.DecomparessFile(path, appAbsolutePath); string[] searchLog = Directory.GetFiles(appAbsolutePath, @"*.log", SearchOption.TopDirectoryOnly); if (searchLog.Length > 0) { for (int i = 0; i < searchLog.Length; i++) { if (Regex.Match(System.IO.Path.GetFileName(searchLog[i]), @"^AppZipPackage_{\w{8}-(\w{4}-){3}\w{12}}.log$").Success) { logFile = searchLog[i]; break; } } if (logFile.Length > 0) { //成功取得log文件 using (StreamReader sr = new StreamReader(new FileStream(logFile, FileMode.Open, FileAccess.Read), Encoding.UTF8)) { String line; while ((line = sr.ReadLine()) != null) { if (line.StartsWith("APP Name:")) { appName = line.Substring(9); continue; } if (line.StartsWith("APP DesCription:")) { appDescription = line.Substring(16); continue; } if (line.StartsWith("App Relative Path:")) { appRelativePath = line.Substring(18); continue; } } } if (appName.Length > 0 && appDescription.Length > 0 && appRelativePath.Length > 0) { //加入列表,调用主窗口线程 this.Dispatcher.Invoke( new Action( delegate { getAppsModel[appTabControl.SelectedIndex].appItems.Add( new AppItem { AppName = appName, AppDescription = appDescription, AppGUID = Guid.NewGuid().ToString("B"), AppZipPath = appZipPath, AppPath = appRelativePath }); })); } else { Directory.Delete(appAbsolutePath); this.ShowModalMessageExternal("Error", "Log file is bad for .appZip file.\nQuit!", MessageDialogStyle.Affirmative); } } else { Directory.Delete(appAbsolutePath); this.ShowModalMessageExternal("Error", "Log missing for .appZip file.\nQuit!", MessageDialogStyle.Affirmative); } } else { Directory.Delete(appAbsolutePath, true); this.ShowModalMessageExternal("Error", "Log missing for .appZip file.\nQuit!", MessageDialogStyle.Affirmative); } } catch (Exception ex) { this.Dispatcher.Invoke((Action) delegate { throw ex; }); } }, "Waiting...", "Unziping package..."); } } } }