public static string GetResourceString(string Type, string Name) { string Result = null; try { byte[] Data = Manipulator.GetResource(Type, Name); Result = System.Text.Encoding.UTF8.GetString(Data); } catch (Exception ex) { } return(Result); }
public static BitmapImage GetResourceImage(string Type, string Name) { BitmapImage Result = null; try { byte[] Data = Manipulator.GetResource(Type, Name); Result = ByteArrayToImage(Data); } catch (Exception ex) { } return(Result); }
private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e) { // Ask if we want to save, abort on error if (DataContext.IsEditMode && MessageBox.Show("Save changes before exit?", "Sure?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { if (Manipulator.Save() == false) { e.Cancel = true; } } //// Clean up temp files if we're closing //if(e.Cancel == false) // Manipulator.Close(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { string[] args = Environment.GetCommandLineArgs(); var Location = System.Reflection.Assembly.GetExecutingAssembly().Location; ZipFile Zip = null; #region Get ZIP if available IntPtr TargetHandle = IntPtr.Zero; try { TargetHandle = Win32.LoadLibraryEx(Location, IntPtr.Zero, 2); if (TargetHandle == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } var Res = Win32.FindResource(TargetHandle, "Data", "Content"); DataContext.HasContent = Res != IntPtr.Zero; if (Res != IntPtr.Zero) { uint size = Win32.SizeofResource(TargetHandle, Res); IntPtr pt = Win32.LoadResource(TargetHandle, Res); byte[] bPtr = new byte[size]; Marshal.Copy(pt, bPtr, 0, (int)size); var zipStream = new MemoryStream(bPtr); var OutputFolder = DataContext.OutputFolder; ZipInputStream zipInputStream = new ZipInputStream(zipStream); ZipEntry zipEntry = zipInputStream.GetNextEntry(); while (zipEntry != null) { String entryFileName = zipEntry.Name; byte[] buffer = new byte[4096]; // 4K is optimum // Manipulate the output filename here as desired. String fullZipToPath = Path.Combine(OutputFolder, entryFileName); string directoryName = Path.GetDirectoryName(fullZipToPath); if (directoryName.Length > 0) { Directory.CreateDirectory(directoryName); } // Skip directory entry string fileName = Path.GetFileName(fullZipToPath); if (fileName.Length == 0) { zipEntry = zipInputStream.GetNextEntry(); continue; } // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size // of the file, but does not waste memory. // The "using" will close the stream even if an exception occurs. using (FileStream streamWriter = File.Create(fullZipToPath)) { StreamUtils.Copy(zipInputStream, streamWriter, buffer); } zipEntry = zipInputStream.GetNextEntry(); } } } catch (Exception ex) { MessageBox.Show( "Oops! This installer seems to be corrupted! Sorry :(\r\n\r\n" + ex.Message, "Fatal Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { if (TargetHandle != IntPtr.Zero) { Win32.EndUpdateResource(TargetHandle, false); } } #endregion #region Install-Mode if (Zip != null) { IsEditMode = false; } #endregion #region Compilation-Mode else if (args.Length > 1 && File.Exists(args[1]) && args[1].EndsWith(".zip")) { try { IsEditMode = false; Manipulator.Initialize(Location); string OutputPath = System.IO.Path.ChangeExtension(args[1], "exe"); bool Exists = File.Exists(OutputPath); if (!Exists || (Exists && MessageBox.Show($"Ausgabe-Datei \"{OutputPath}\" existiert bereits. Soll die Datei überschrieben werden?", "Überschreiben?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)) { Manipulator.UpdateResource("Content", "Data", File.ReadAllBytes(args[1])); File.Copy(Manipulator.TargetPath, OutputPath, true); } } catch (Exception ex) { MessageBox.Show("Fehler bei der Erstellung des Setups:\r\n" + ex.Message, "Fehler!", MessageBoxButton.OK, MessageBoxImage.Error); } Close(); } #endregion #region Edit-Mode else { IsEditMode = true; Manipulator.Initialize(Location); } #endregion var desc = DependencyPropertyDescriptor.FromProperty(ContentControl.ContentProperty, typeof(UserControl)); desc.AddValueChanged(ContentView, OnPageChanged); DataContext.Pages.Add(new PageIntroViewModel()); DataContext.Pages.Add(new PageLicenseViewModel()); DataContext.Pages.Add(new PageTargetDirectoryViewModel()); DataContext.Pages.Add(new PageInstallViewModel()); DataContext.Pages.Add(new PageCompletionViewModel()); DataContext.CurrentPage = DataContext.Pages.FirstOrDefault(); }