Ejemplo n.º 1
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);
            }
        }