Example #1
0
        //-----------------------------------------------
        // 公共方法
        //-----------------------------------------------
        /// <summary>导出</summary>
        public override object Export(ExportMode type = ExportMode.Normal)
        {
            return(new
            {
                this.FileName,
                this.Url,
                this.FileSizeText,

                ID = type.HasFlag(ExportMode.Detail) ? (long?)this.ID : null,
                Type = type.HasFlag(ExportMode.Detail) ? this.Type : null,
                MimeType = type.HasFlag(ExportMode.Detail) ? this.MimeType : null,
                FileSize = type.HasFlag(ExportMode.Detail) ? this.FileSize : null,
                CreateDt = type.HasFlag(ExportMode.Detail) ? this.CreateDt : null,
                FileExtension = type.HasFlag(ExportMode.Detail) ? this.FileExtension : null,
                FileMD5 = type.HasFlag(ExportMode.Detail) ? this.FileMD5 : null,
                FileVisitCnt = type.HasFlag(ExportMode.Detail) ? this.FileVisitCnt : null,
            });
        }
Example #2
0
    void OnExportStart(string destFile, string projectPath, ExportMode mode)
    {
        var stopwatch = System.Diagnostics.Stopwatch.StartNew();

        exporting = true;
        var  files         = new List <string>();
        long totalFileSize = 0;;
        long totalWritten  = 0;

        files.AddRange(Directory.GetFiles(Path.Combine(projectPath, SaveFile.extraPath)));
        files.AddRange(Directory.GetFiles(Path.Combine(projectPath, SaveFile.miniaturesPath)));
        files.Add(Path.Combine(projectPath, SaveFile.metaFilename));
        files.Add(Path.Combine(projectPath, SaveFile.chaptersFilename));
        files.Add(Path.Combine(projectPath, SaveFile.tagsFilename));

        //NOTE(Simon): If mode is "full", also include the base video and thumb image
        if (mode.HasFlag(ExportMode.Full))
        {
            files.Add(Path.Combine(projectPath, SaveFile.thumbFilename));
            files.Add(Path.Combine(projectPath, SaveFile.videoFilename));
        }

        //NOTE(Simon): If mode is "editable", also include the editable file
        if (mode.HasFlag(ExportMode.AllowEdit))
        {
            files.Add(Path.Combine(projectPath, SaveFile.editableFilename));
        }

        //NOTE(Simon): If zip exists, delete the original, so we don't keep old archive entries around
        File.Delete(destFile);

        foreach (var file in files)
        {
            totalFileSize += new FileInfo(file).Length;
        }
        using (var dest = new ZipArchive(File.OpenWrite(destFile), ZipArchiveMode.Create))
        {
            foreach (string file in files)
            {
                string filenameInZip = file.Substring(projectPath.Length + 1);

                var entry = dest.CreateEntry(filenameInZip, System.IO.Compression.CompressionLevel.NoCompression);

                using (var stream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                    using (var entryStream = entry.Open())
                    {
                        //NOTE(Simon): 80kB is the buffer size used in .NET's CopyTo()
                        var buffer = new byte[80 * 1024];
                        int read;
                        do
                        {
                            read = stream.Read(buffer, 0, buffer.Length);
                            entryStream.Write(buffer, 0, read);
                            totalWritten += read;
                            progress      = (float)totalWritten / totalFileSize;
                        } while (read > 0);
                    }
            }
        }

        stopwatch.Stop();
        Debug.Log(stopwatch.Elapsed.TotalSeconds + "s");
        Debug.Log(totalWritten / stopwatch.Elapsed.TotalSeconds / 1024 / 1024 + "MB/s");

        OnExportEnd(destFile);
    }