コード例 #1
0
            public TempFile(FileEntry entry, PackageFileEntry be = null, FormatConverter converter = null, string filePath = null, bool includeInnerPath = true)
            {
                string path;

                if (includeInnerPath)
                {
                    path = entry.EntryPath.Replace("/", "\\");
                }
                else
                {
                    path = entry.Name;
                }

                if (filePath == null)
                {
                    FilePath = Path.Combine(Path.GetTempPath(), "DBV", path);
                    if (converter != null && converter.Extension != null)
                    {
                        FilePath += "." + converter.Extension;
                    }
                }
                else
                {
                    FilePath = filePath;
                }

                SaveFile(entry, FilePath, converter, be, true);

                Entry = be;
                if (converter != null)
                {
                    ExporterKey = converter.Key;
                }
            }
コード例 #2
0
        public static void DoViewFile(FileEntry entry, PackageFileEntry be = null, FormatConverter exporter = null)
        {
            try
            {
                if (entry.BundleEntries.Count == 0)
                {
                    return;
                }

                TempFile temp = GetTempFile(entry, be, exporter);
                GC.Collect();
                Process proc = new Process();
                proc.StartInfo.FileName  = "explorer";
                proc.StartInfo.Arguments = $"\"{temp.FilePath}\"";
                proc.Start();
                if (!TempFiles.ContainsKey(entry))
                {
                    TempFiles.Add(entry, temp);
                }
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                Console.WriteLine(exc.StackTrace);
            }
        }
コード例 #3
0
        public static void SaveFileConvert(FileEntry file, string removeDirectory)
        {
            SaveFileDialog sfd = new SaveFileDialog {
                FileName = file.Name
            };

            string typ = Definitions.TypeFromExtension(file.ExtensionIds.ToString());

            if (ScriptActions.Converters.ContainsKey(typ))
            {
                var    convs     = ScriptActions.Converters[typ];
                string filter    = "";
                var    conerters = new List <FormatConverter>();
                foreach (var pair in convs)
                {
                    FormatConverter conv = pair.Value;
                    filter += $"{conv.Title} (*.{conv.Extension})|*.{conv.Extension}|";
                    conerters.Add(conv);
                }
                sfd.Filter = filter.Remove(filter.Length - 1); // + "|All files (*.*)|*.*";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    string filePath = Path.Combine(Utils.GetDirectory(file.EntryPath), sfd.FileName);
                    if (!Settings.Data.ExtractFullDir && !string.IsNullOrEmpty(removeDirectory))
                    {
                        filePath = filePath.Replace(removeDirectory.Replace("/", "\\") + "\\", "");
                    }
                    SaveFile(file, filePath, conerters[sfd.FilterIndex - 1]);
                }
            }
        }
コード例 #4
0
        public static void ConvertFile(FileEntry entry, Action <FormatConverter> done)
        {
            if (entry.BundleEntries.Count == 0)
            {
                Console.WriteLine("No bundle entries.");
                return;
            }

            string typ = Definitions.TypeFromExtension(entry.ExtensionIds.ToString());

            if (ScriptActions.Converters.ContainsKey(typ))
            {
                var convs = ScriptActions.Converters[typ];

                //Don't open the dialog for things that are just an extension change
                if (convs.Count == 1)
                {
                    FormatConverter format = convs.First().Value;
                    if (!format.RequiresAttention)
                    {
                        done(format);
                        return;
                    }
                }

                var formats = convs.Values.ToList();
                formats.Add(new FormatConverter {
                    Title = "None"
                });

                DialogParameters pms = new DialogParameters
                {
                    { "Formats", formats }
                };
                Utils.CurrentDialogService.ShowDialog("ConvertFileDialog", pms, r =>
                {
                    if (r.Result == ButtonResult.OK)
                    {
                        FormatConverter selected = pms.GetValue <FormatConverter>("Format");
                        done(selected.Title == "None" ? null : selected);
                    }
                });
            }
            else
            {
                done(null);
            }
        }
コード例 #5
0
        public static void SaveFile(FileEntry file, string path, FormatConverter converter = null, PackageFileEntry be = null, bool checkIfExists = false)
        {
            if (checkIfExists && File.Exists(path))
            {
                return;
            }

            object file_data = file.FileData(be, converter);

            string dir = Path.GetDirectoryName(path);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (file_data is byte[] v)
            {
                File.WriteAllBytes(path, v);
            }
            else if (file_data is Stream fs)
            {
                if (converter != null && converter.SaveEvent != null)
                {
                    converter.SaveEvent(fs, path);
                }
                else
                {
                    using FileStream file_stream = File.Create(path);
                    fs.CopyTo(file_stream);
                    fs.Close();
                }
            }
            else if (file_data is string dataStr)
            {
                File.WriteAllText(path, dataStr);
            }
            else if (file_data is string[] dataArr)
            {
                File.WriteAllLines(path, dataArr);
            }
        }
コード例 #6
0
        public static void AddConverter(FormatConverter format)
        {
            if (format.Key == null)
            {
                Console.WriteLine("[ERROR] Converter must have a key variable!");
                return;
            }

            if (!Converters.ContainsKey(format.Type))
            {
                Converters.Add(format.Type, new Dictionary <string, FormatConverter>());
            }

            if (Converters[format.Type].ContainsKey(format.Key))
            {
                Console.WriteLine("[ERROR] Conveter is already registered with key {0}", format.Key);
                return;
            }

            Converters[format.Type].Add(format.Key, format);
        }
コード例 #7
0
        public static TempFile GetTempFile(FileEntry file, PackageFileEntry entry = null, FormatConverter exporter = null)
        {
            TempFile path;

            if (!TempFiles.ContainsKey(file) || TempFiles[file].Disposed || !File.Exists(TempFiles[file].FilePath) || (exporter != null && TempFiles[file].ExporterKey != exporter.Key) || TempFiles[file].Entry != entry)
            {
                if (TempFiles.ContainsKey(file))
                {
                    DeleteTempFile(file);
                }

                path = CreateTempFile(file, entry, exporter);
            }
            else
            {
                path = TempFiles[file];
            }

            return(path);
        }
コード例 #8
0
        public static TempFile CreateTempFile(FileEntry entry, PackageFileEntry be = null, FormatConverter exporter = null)
        {
            if (TempFiles.ContainsKey(entry))
            {
                DeleteTempFile(entry);
            }

            TempFile temp = new TempFile(entry, be, exporter);

            return(temp);
        }