| | |
| | | using Autodesk.Revit.DB;
|
| | | using HStation.RevitDev.RevitDataExport.Common;
|
| | | using HStation.RevitDev.RevitDataExport.Entity;
|
| | | using ICSharpCode.SharpZipLib.Zip;
|
| | | using System;
|
| | | using System.IO;
|
| | | using System.Linq;
|
| | | using System.Windows.Forms;
|
| | |
|
| | | namespace HStation.RevitDev.RevitDataExport.Utility
|
| | | {
|
| | |
| | | File.WriteAllText(GlobalResource.RecordFilePath, config);
|
| | | }
|
| | |
|
| | | public static bool ExportZipFile(Document _doc)
|
| | | {
|
| | | FolderBrowserDialog dialog = new FolderBrowserDialog();
|
| | | if (dialog.ShowDialog() == DialogResult.OK)
|
| | | {
|
| | | try
|
| | | {
|
| | | var zipFilePath = dialog.SelectedPath + "\\model.ywrvt";
|
| | |
|
| | | var tempDir = "d:\\temp";
|
| | | if (!Directory.Exists(tempDir))
|
| | | Directory.CreateDirectory(tempDir);
|
| | | var structFile = tempDir + "\\struct.json";
|
| | | var modelFile = tempDir + "\\model.rvt";
|
| | | var settingFile = tempDir + "\\setting.json";
|
| | | if (File.Exists(structFile)) File.Delete(structFile);
|
| | | if (File.Exists(modelFile)) File.Delete(modelFile);
|
| | | if (!File.Exists(settingFile)) File.Create(settingFile).Close();
|
| | | File.Copy(_doc.PathName, modelFile);
|
| | | File.Copy(GlobalResource.RecordFilePath, structFile);
|
| | |
|
| | | var setting = new SettingsViewModel() { Version = "1" };
|
| | | File.WriteAllText(settingFile, JsonHelper.ToJson(setting));
|
| | |
|
| | | var files = new string[] { structFile, modelFile, settingFile };
|
| | | ZipFiles(files, zipFilePath);
|
| | |
|
| | | File.Delete(structFile);
|
| | | File.Delete(modelFile);
|
| | | File.Delete(settingFile);
|
| | | return true;
|
| | | }
|
| | | catch (Exception ex) |
| | | { |
| | | return false; |
| | | }
|
| | |
|
| | | }
|
| | | return true;
|
| | |
|
| | | }
|
| | |
|
| | | private static void ZipFiles(string[] files, string zipFilePath)
|
| | | {
|
| | | using (var zipOutputStream = new ZipOutputStream(File.Create(zipFilePath)))
|
| | | {
|
| | | zipOutputStream.SetLevel(9); // 设置压缩级别
|
| | |
|
| | | foreach (var file in files)
|
| | | {
|
| | | var entry = new ZipEntry(Path.GetFileName(file))
|
| | | {
|
| | | DateTime = DateTime.Now,
|
| | | Size = File.ReadAllBytes(file).Length
|
| | | };
|
| | |
|
| | | zipOutputStream.PutNextEntry(entry);
|
| | |
|
| | | using (var fileStream = File.OpenRead(file))
|
| | | {
|
| | | int sourceBytes;
|
| | | byte[] buffer = new byte[4096];
|
| | |
|
| | | while ((sourceBytes = fileStream.Read(buffer, 0, buffer.Length)) > 0)
|
| | | {
|
| | | zipOutputStream.Write(buffer, 0, sourceBytes);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | zipOutputStream.Finish();
|
| | | zipOutputStream.Close();
|
| | | }
|
| | | }
|
| | |
|
| | | public static void HideOrShowModels(Document document)
|
| | | {
|
| | | if (document == null) { return; }
|