public bool Load(string folder, string imagePath) { try { _imagePath = imagePath; if (File.Exists(Path.Combine(folder, _imagePath) + ".dds")) { _image = LoadImage(folder, _imagePath, ".dds"); if (_size.Height != _size.Width) { _image = CropImage(_image, _size); } return(true); } return(false); } catch (Exception ex) { ExceptionLogger.LogException(ex); return(false); } }
public Image GetImage(Size size, string imagePath) { try { ImageHolder image = _imageHolder.Find(tmp => tmp.ImagePath == imagePath); if (image != null) { return(image.Image); } image = new ImageHolder(size, fileManager); if (image.Load(_basePath, imagePath)) { _imageHolder.Add(image); return(image.Image); } return(null); } catch (Exception ex) { ExceptionLogger.LogException(ex); return(null); } }
public Image GetImage(int unitType) { try { ImageHolder image = _imageHolder.Find(tmp => tmp.UnitType == unitType); if (image != null) { return(image.Image); } image = new ImageHolder(new Size(8, 8), fileManager); if (image.Load("items", unitType)) { _imageHolder.Add(image); return(image.Image); } return(null); } catch (Exception ex) { ExceptionLogger.LogException(ex); return(null); } }
/// <summary> /// Loads the bitmap from the in game files /// </summary> /// <param name="imagePath">The path to the image</param> /// <returns>Returns "true" if the image was found, "false" if not.</returns> public bool LoadFromGameFiles(string imagePath) { try { _imagePath = imagePath; _image = LoadImage(_imagePath, ".dds"); if (_size.Height != _size.Width) { _image = CropImage(_image, _size); } return(true); } catch (Exception ex) { ExceptionLogger.LogException(ex); return(false); } }
private Bitmap CropImage(Bitmap bmp, Size size) { try { int sizeX = size.Width * 68; int sizeY = size.Height * 68; int posX = (256 - sizeX) / 2; int posY = (256 - sizeY) / 2; Rectangle rect = new Rectangle(posX, posY, sizeX, sizeY); Bitmap tmp = bmp.Clone(rect, bmp.PixelFormat); bmp.Dispose(); return(tmp); } catch (Exception ex) { ExceptionLogger.LogException(ex); return(null); } }
/// <summary> /// User-friendly uncooking of Tree Node list. /// </summary> /// <param name="progressForm">A progress form to update.</param> /// <param name="param">The Tree Node List.</param> private void _DoUnooking(ProgressForm progressForm, Object param) { List <TreeNode> uncookingNodes = (List <TreeNode>)param; const int progressUpdateFreq = 20; if (progressForm != null) { progressForm.ConfigBar(1, uncookingNodes.Count, progressUpdateFreq); } int i = 0; foreach (TreeNode treeNode in uncookingNodes) { NodeObject nodeObject = (NodeObject)treeNode.Tag; PackFileEntry fileEntry = nodeObject.FileEntry; // update progress if applicable if (i % progressUpdateFreq == 0 && progressForm != null) { progressForm.SetCurrentItemText(fileEntry.Path); } i++; // get the file bytes String relativePath = fileEntry.Path; byte[] fileBytes; try { fileBytes = _fileManager.GetFileBytes(fileEntry, true); if (fileBytes == null) { continue; } } catch (Exception e) { ExceptionLogger.LogException(e); continue; } // determine file type HellgateFile hellgateFile; if (relativePath.EndsWith(XmlCookedFile.Extension)) { hellgateFile = new XmlCookedFile(_fileManager); } else if (relativePath.EndsWith(RoomDefinitionFile.Extension)) { hellgateFile = new RoomDefinitionFile(relativePath); } else if (relativePath.EndsWith(MLIFile.Extension)) { hellgateFile = new MLIFile(); } else { Debug.Assert(false, "wtf"); continue; } // deserialise file DialogResult dr = DialogResult.Retry; bool uncooked = false; while (dr == DialogResult.Retry && !uncooked) { try { hellgateFile.ParseFileBytes(fileBytes); uncooked = true; } catch (Exception e) { ExceptionLogger.LogException(e, true); String errorMsg = String.Format("Failed to uncooked file!\n{0}\n\n{1}", relativePath, e); dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); if (dr == DialogResult.Abort) { return; } if (dr == DialogResult.Ignore) { break; } } } if (!uncooked) { continue; } // save file String relativeSavePath = relativePath.Replace(HellgateFile.Extension, HellgateFile.ExtensionDeserialised); String savePath = Path.Combine(Config.HglDir, relativeSavePath); dr = DialogResult.Retry; bool saved = false; byte[] documentBytes = null; while (dr == DialogResult.Retry && !saved) { try { if (documentBytes == null) { documentBytes = hellgateFile.ExportAsDocument(); } File.WriteAllBytes(savePath, documentBytes); saved = true; } catch (Exception e) { ExceptionLogger.LogException(e, true); String errorMsg = String.Format("Failed to save file!\n{0}\n\n{1}", relativePath, e); dr = MessageBox.Show(errorMsg, "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Exclamation); if (dr == DialogResult.Abort) { return; } if (dr == DialogResult.Ignore) { break; } } } // update tree view TreeNode newTreeNode = new TreeNode(); NodeObject newNodeObject = new NodeObject { CanEdit = true, IsUncookedVersion = true }; newTreeNode.Tag = newNodeObject; treeNode.Nodes.Add(newTreeNode); } }