Example #1
0
        private void WriteSoundProp(string wzPath, WzSoundProperty soundProp, AWzObject uol, bool uolDirCopy, string overridePath)
        {
            string fileName    = CleanFileName(uol != null && !uolDirCopy ? uol.Name : soundProp.Name);
            string newFilePath = overridePath ?? Path.Combine(ExtractPath, wzPath, fileName + ".mp3");

            CreateDirectory(ref wzPath);
            Form.UpdateToolstripStatus("Dumping " + soundProp.Name + ".mp3 to " + wzPath);
            using (var stream = new FileStream(newFilePath, FileMode.Create, FileAccess.Write)) {
                stream.Write(soundProp.GetBytes(), 0, soundProp.GetBytes().Length);
            }
        }
Example #2
0
        private void DumpCanvasProp(string wzPath, WzCanvasProperty canvasProp, AWzObject uol, bool uolDirCopy)
        {
            string fileName    = CleanFileName(uol != null && !uolDirCopy ? uol.Name : canvasProp.Name);
            string newFilePath = Path.Combine(ExtractPath, wzPath, fileName + ".png");

            if (LinkType != LinkType.Copy && !(string.IsNullOrEmpty(canvasProp.Outlink) && string.IsNullOrEmpty(canvasProp.Inlink) && uol == null))
            {
                string targetFile;
                if (!string.IsNullOrEmpty(canvasProp.Inlink))
                {
                    targetFile = Path.Combine(CurrentImageDir, canvasProp.Inlink + ".png");
                }
                else if (!string.IsNullOrEmpty(canvasProp.Outlink))
                {
                    targetFile = Path.Combine(WzFolderName, canvasProp.Outlink.Substring(canvasProp.Outlink.IndexOf("/", StringComparison.OrdinalIgnoreCase) + 1) + ".png");
                }
                else
                {
                    targetFile = Path.Combine(WzFolderName, canvasProp.FullPath.Substring(canvasProp.FullPath.IndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1) + ".png");
                }
                SanitizeTargetPath(ref targetFile);
                FileInfo file       = new FileInfo(targetFile);
                bool     createLink = true;
                if (!File.Exists(targetFile))
                {
                    createLink = WritePng(wzPath, fileName, targetFile, canvasProp, file);
                }
                if (createLink)
                {
                    FileInfo linkPath = new FileInfo(newFilePath);
                    linkPath.Directory.Create();
                    bool res = LinkType == LinkType.Symbolic ? CreateSymbolicLink(newFilePath, targetFile, 0) : CreateHardLink(newFilePath, targetFile, IntPtr.Zero);
                    if (!res)
                    {
                        uint error = GetLastError();
                        if (error == 1142) // max links reached for file, fallback to copy mode
                        {
                            WritePng(wzPath, fileName, newFilePath, canvasProp);
                        }
                        else if (error != 183) // link already exists
                        {
                            Form.UpdateTextBoxInfo(Form.InfoTextBox, "Error creating link: " + error + " - " + newFilePath + " -> " + targetFile, true);
                        }
                    }
                }
            }
            else
            {
                WritePng(wzPath, fileName, newFilePath, canvasProp);
            }
        }
Example #3
0
        private void DumpFromUOL(AWzObject uolProp, AWzImageProperty obj, string wzPath, bool copyName = false)
        {
            var name = copyName ? obj.Name : uolProp.Name;

            switch (obj.PropertyType)
            {
            case WzPropertyType.Canvas:
                var uolPngProp = (WzCanvasProperty)obj;
                DumpCanvasProp(wzPath, uolPngProp, uolProp, copyName);
                break;

            case WzPropertyType.SubProperty:
                var uolSubProp = (WzSubProperty)obj;
                var subDir     = Path.Combine(wzPath, CleanFileName(name));
                if (LinkType == LinkType.Symbolic)
                {
                    string linkPath  = Path.Combine(ExtractPath, subDir);
                    string targetDir = Path.Combine(WzFolderName, uolSubProp.FullPath.Substring(uolSubProp.FullPath.IndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1));
                    Directory.CreateDirectory(Directory.GetParent(linkPath).FullName);
                    CreateDirectory(ref targetDir);
                    bool res = CreateSymbolicLink(linkPath, Path.Combine(ExtractPath, targetDir), 1);
                    if (!res)
                    {
                        uint error = GetLastError();
                        if (error != 183)
                        {
                            Form.UpdateTextBoxInfo(Form.InfoTextBox, "Error creating link: " + GetLastError() + " - " + linkPath + " -> " + targetDir, true);
                        }
                    }
                }
                else
                {
                    foreach (var file in uolSubProp.WzProperties)
                    {
                        DumpFromUOL(uolProp, file, subDir, true);
                    }
                }
                break;

            case WzPropertyType.Sound:
                name = CleanFileName(name);
                var uolSoundProp = (WzSoundProperty)obj;
                CreateDirectory(ref wzPath);
                if (LinkType != LinkType.Copy)
                {
                    string linkPath   = Path.Combine(ExtractPath, wzPath, name + ".mp3");
                    string targetFile = Path.Combine(WzFolderName, uolSoundProp.FullPath.Substring(uolSoundProp.FullPath.IndexOf("\\", StringComparison.OrdinalIgnoreCase) + 1) + ".mp3");
                    SanitizeTargetPath(ref targetFile);
                    FileInfo file = new FileInfo(targetFile);
                    if (!File.Exists(targetFile))
                    {
                        file.Directory.Create();
                        WriteSoundProp(wzPath, uolSoundProp, uolProp, copyName, targetFile);
                    }
                    bool res = LinkType == LinkType.Symbolic ? CreateSymbolicLink(linkPath, targetFile, 0) : CreateHardLink(linkPath, targetFile, IntPtr.Zero);
                    if (!res)
                    {
                        uint error = GetLastError();
                        if (error == 1142)
                        {
                            WriteSoundProp(wzPath, uolSoundProp, uolProp, copyName, null);
                        }
                        else if (error != 183)
                        {
                            Form.UpdateTextBoxInfo(Form.InfoTextBox, "Error creating link: " + error + " - " + linkPath + " -> " + targetFile, true);
                        }
                    }
                }
                else
                {
                    WriteSoundProp(wzPath, uolSoundProp, uolProp, copyName, null);
                }
                break;

            case WzPropertyType.UOL:
                var subUOL = (WzUOLProperty)obj;
                var uolVal = subUOL.LinkValue;
                if (uolVal != null)
                {
                    DumpFromUOL(subUOL, uolVal, wzPath, false);
                }
                break;
            }
        }