private bool OpenWzFile(string path, WzMapleVersion encVersion, short version, out WzFile file) { try { WzFile f = new WzFile(path, version, encVersion); lock (wzFiles) { wzFiles.Add(f); } WzFileParseStatus parseStatus = f.ParseWzFile(); if (parseStatus != WzFileParseStatus.Success) { file = null; Warning.Error("Error initializing " + Path.GetFileName(path) + " (" + parseStatus.GetErrorDescription() + ")."); return(false); } file = f; return(true); } catch (Exception e) { Warning.Error("Error initializing " + Path.GetFileName(path) + " (" + e.Message + ").\r\nAlso, check that the directory is valid and the file is not in use."); file = null; return(false); } }
/// <summary> /// Adds a WzObject to the WzNode and returns the newly created WzNode /// </summary> /// <param name="obj"></param> /// <param name="undoRedoMan"></param> /// <returns></returns> public WzNode AddObject(WzObject obj, UndoRedoManager undoRedoMan) { if (CanNodeBeInserted(this, obj.Name)) { TryParseImage(); if (addObjInternal(obj)) { WzNode node = new WzNode(obj, true); Nodes.Add(node); if (node.Tag is WzImageProperty) { ((WzImageProperty)node.Tag).ParentImage.Changed = true; } undoRedoMan.AddUndoBatch(new System.Collections.Generic.List <UndoRedoAction> { UndoRedoManager.ObjectAdded(this, node) }); node.EnsureVisible(); return(node); } else { Warning.Error("Could not insert property, make sure all types are correct"); return(null); } } else { MessageBox.Show("Cannot insert object \"" + obj.Name + "\" because an object with the same name already exists. Skipping.", "Skipping Object", MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } }
public static bool PrepareApplication(bool from_internal) { _ConfigurationManager = new ConfigurationManager(); bool loaded = _ConfigurationManager.Load(); if (!loaded) { Warning.Error(HaRepacker.Properties.Resources.ProgramLoadSettingsError); return(true); } bool firstRun = Program.ConfigurationManager.ApplicationSettings.FirstRun; if (Program.ConfigurationManager.ApplicationSettings.FirstRun) { //new FirstRunForm().ShowDialog(); Program.ConfigurationManager.ApplicationSettings.FirstRun = false; _ConfigurationManager.Save(); } if (Program.ConfigurationManager.UserSettings.AutoAssociate && from_internal && IsUserAdministrator()) { string path = Application.ExecutablePath; Registry.ClassesRoot.CreateSubKey(".wz").SetValue("", "WzFile"); RegistryKey wzKey = Registry.ClassesRoot.CreateSubKey("WzFile"); wzKey.SetValue("", "Wz File"); wzKey.CreateSubKey("DefaultIcon").SetValue("", path + ",1"); wzKey.CreateSubKey("shell\\open\\command").SetValue("", "\"" + path + "\" \"%1\""); } return(firstRun); }
public static bool PrepareApplication(bool from_internal) { SettingsManager = new WzSettingsManager(GetLocalSettingsPath(), typeof(UserSettings), typeof(ApplicationSettings)); bool loaded = false; for (int i = 0; i < 5; i++) { try { SettingsManager.Load(); loaded = true; break; } catch { Thread.Sleep(1000); } } if (!loaded) { Warning.Error(HaRepacker.Properties.Resources.ProgramLoadSettingsError); return(true); } bool firstRun = ApplicationSettings.FirstRun; if (ApplicationSettings.FirstRun) { //new FirstRunForm().ShowDialog(); ApplicationSettings.FirstRun = false; SettingsManager.Save(); } if (UserSettings.AutoAssociate && from_internal && IsUserAdministrator()) { string path = Application.ExecutablePath; Registry.ClassesRoot.CreateSubKey(".wz").SetValue("", "WzFile"); RegistryKey wzKey = Registry.ClassesRoot.CreateSubKey("WzFile"); wzKey.SetValue("", "Wz File"); wzKey.CreateSubKey("DefaultIcon").SetValue("", path + ",1"); wzKey.CreateSubKey("shell\\open\\command").SetValue("", "\"" + path + "\" \"%1\""); } return(firstRun); }
public static bool PrepareApplication() { SettingsManager = new WzSettingsManager(System.IO.Path.Combine(Application.StartupPath, "HRSettings.wz"), typeof(UserSettings), typeof(ApplicationSettings)); int tryCount = 0; tryagain: try { SettingsManager.Load(); } catch { tryCount++; if (tryCount < 5) { Thread.Sleep(1000); goto tryagain; } else { Warning.Error("Could not load settings file, make sure it is not in use. If it is not, delete it and try again."); return(true); } } bool firstRun = ApplicationSettings.FirstRun; if (ApplicationSettings.FirstRun) { new FirstRunForm().ShowDialog(); ApplicationSettings.FirstRun = false; SettingsManager.Save(); } if (UserSettings.AutoAssociate) { string path = Application.ExecutablePath; Registry.ClassesRoot.CreateSubKey(".wz").SetValue("", "WzFile"); RegistryKey wzKey = Registry.ClassesRoot.CreateSubKey("WzFile"); wzKey.SetValue("", "Wz File"); wzKey.CreateSubKey("DefaultIcon").SetValue("", path + ",1"); wzKey.CreateSubKey("shell\\open\\command").SetValue("", "\"" + path + "\" \"%1\""); } return(firstRun); }
public static void ExtractAnimation(WzSubProperty parent, string savePath, bool apngFirstFrame) { List <Bitmap> bmpList = new List <Bitmap>(parent.WzProperties.Count); List <int> delayList = new List <int>(parent.WzProperties.Count); Point biggestPng = new Point(0, 0); Point SmallestEmptySpace = new Point(65535, 65535); Point MaximumPngMappingEndingPts = new Point(0, 0); foreach (WzImageProperty subprop in parent.WzProperties) { if (subprop is WzCanvasProperty) { //System.Drawing.PointF origin = ((WzCanvasProperty)subprop).GetCanvasOriginPosition(); WzPngProperty png = ((WzCanvasProperty)subprop).PngProperty; if (png.Height > biggestPng.Y) { biggestPng.Y = png.Height; } if (png.Width > biggestPng.X) { biggestPng.X = png.Width; } } } List <WzCanvasProperty> sortedProps = new List <WzCanvasProperty>(); foreach (WzImageProperty subprop in parent.WzProperties) { if (subprop is WzCanvasProperty property) { sortedProps.Add(property); WzPngProperty png = property.PngProperty; System.Drawing.PointF origin = property.GetCanvasOriginPosition(); Point StartPoints = new Point(biggestPng.X - (int)origin.X, biggestPng.Y - (int)origin.Y); Point PngMapppingEndingPts = new Point(StartPoints.X + png.Width, StartPoints.Y + png.Height); if (StartPoints.X < SmallestEmptySpace.X) { SmallestEmptySpace.X = StartPoints.X; } if (StartPoints.Y < SmallestEmptySpace.Y) { SmallestEmptySpace.Y = StartPoints.Y; } if (PngMapppingEndingPts.X > MaximumPngMappingEndingPts.X) { MaximumPngMappingEndingPts.X = PngMapppingEndingPts.X; } if (PngMapppingEndingPts.Y > MaximumPngMappingEndingPts.Y) { MaximumPngMappingEndingPts.Y = PngMapppingEndingPts.Y; } } } sortedProps.Sort(new Comparison <WzCanvasProperty>(PropertySorter)); for (int i = 0; i < sortedProps.Count; i++) { WzCanvasProperty subprop = sortedProps[i]; if (i.ToString() != subprop.Name) { Warning.Error(string.Format(Properties.Resources.AnimError, i.ToString())); return; } Bitmap bmp = subprop.PngProperty.GetImage(false); System.Drawing.PointF origin = subprop.GetCanvasOriginPosition(); bmpList.Add(OptimizeBitmapTransparent(bmp, new WzVectorProperty("", origin.X, origin.Y), biggestPng, SmallestEmptySpace, MaximumPngMappingEndingPts)); int?delay = subprop[WzCanvasProperty.AnimationDelayPropertyName]?.GetInt(); if (delay == null) { delay = 100; } delayList.Add((int)delay); } SharpApng apngBuilder = new SharpApng(); if (apngFirstFrame) { apngBuilder.AddFrame(new SharpApngFrame(CreateIncompatibilityFrame(new Size(bmpList[0].Width, bmpList[0].Height)), 1, 1)); } for (int i = 0; i < bmpList.Count; i++) { apngBuilder.AddFrame(new SharpApngFrame(bmpList[i], GetNumByDelay(delayList[i]), GetDenByDelay(delayList[i]))); } apngBuilder.WriteApng(savePath, apngFirstFrame, true); }