Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Change bcfzip extension to bcf according to version 2.1 documentation #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions Bcfier/Bcf/BcfContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public BcfContainer()
BcfFiles = new ObservableCollection<BcfFile>();
}


public ObservableCollection<BcfFile> BcfFiles
{
get
Expand Down Expand Up @@ -179,8 +178,15 @@ public void UpdateDropdowns()

}

public static string FileExtension
{
get { return ".bcf"; }
}


public static string FileFilter
{
get { return String.Format("BIM Collaboration Format (*{0})|*{0}", FileExtension); }
}

#region private methods
/// <summary>
Expand All @@ -191,14 +197,17 @@ private static IEnumerable<BcfFile> OpenBcfDialog()
{
try
{
var openFileDialog1 = new Microsoft.Win32.OpenFileDialog();
openFileDialog1.Filter = "BIM Collaboration Format (*.bcfzip)|*.bcfzip";
openFileDialog1.DefaultExt = ".bcfzip";
openFileDialog1.Multiselect = true;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
var result = openFileDialog1.ShowDialog(); // Show the dialog.
var openFileDialog1 = new Microsoft.Win32.OpenFileDialog
{
Title = String.Format("Open BCF file ({0})", FileExtension),
Filter = FileFilter,
DefaultExt = FileExtension,
Multiselect = true,
RestoreDirectory = true,
CheckFileExists = true,
CheckPathExists = true
};
var result = openFileDialog1.ShowDialog(); // Show the dialog.

if (result == true) // Test result.
{
Expand All @@ -213,38 +222,37 @@ private static IEnumerable<BcfFile> OpenBcfDialog()
}

/// <summary>
/// Logic that extracts files from a bcfzip and deserializes them
/// Logic that extracts files from a bcf file and deserializes them
/// </summary>
/// <param name="bcfzipfile">Path to the .bcfzip file</param>
/// <param name="bcffile">Path to the .bcf file</param>
/// <returns></returns>
private static BcfFile OpenBcfFile(string bcfzipfile)
private static BcfFile OpenBcfFile(string filePath)
{
var bcffile = new BcfFile();
var file = new BcfFile();
try
{
if (!File.Exists(bcfzipfile) || !String.Equals(Path.GetExtension(bcfzipfile), ".bcfzip", StringComparison.InvariantCultureIgnoreCase))
return bcffile;
if (!File.Exists(filePath) || !String.Equals(Path.GetExtension(filePath), FileExtension, StringComparison.InvariantCultureIgnoreCase))
return file;

file.Filename = Path.GetFileNameWithoutExtension(filePath);
file.Fullname = filePath;

bcffile.Filename = Path.GetFileNameWithoutExtension(bcfzipfile);
bcffile.Fullname = bcfzipfile;

using (ZipArchive archive = ZipFile.OpenRead(bcfzipfile))
using (ZipArchive archive = ZipFile.OpenRead(filePath))
{
archive.ExtractToDirectory(bcffile.TempPath);
archive.ExtractToDirectory(file.TempPath);
}

var dir = new DirectoryInfo(bcffile.TempPath);
var dir = new DirectoryInfo(file.TempPath);

var projectFile = Path.Combine(bcffile.TempPath, "project.bcfp");
var projectFile = Path.Combine(file.TempPath, "project.bcfp");
if (File.Exists(projectFile))
{
var project = DeserializeProject(projectFile);
var g = Guid.NewGuid();
Guid.TryParse(project.Project.ProjectId, out g);
bcffile.ProjectId = g;
file.ProjectId = g;
}


//ADD ISSUES FOR EACH SUBFOLDER

Expand Down Expand Up @@ -307,23 +315,23 @@ private static BcfFile OpenBcfFile(string bcfzipfile)
//it is needed since deserialization overwrites the ones set in the constructor
bcfissue.RegisterEvents();
//ViewComment stuff
bcffile.Issues.Add(bcfissue);
file.Issues.Add(bcfissue);
}
try
{
bcffile.Issues = new ObservableCollection<Markup>(bcffile.Issues.OrderBy(x => x.Topic.Index));
file.Issues = new ObservableCollection<Markup>(file.Issues.OrderBy(x => x.Topic.Index));
}
catch { }
}
catch (System.Exception ex1)
{
MessageBox.Show("exception: " + ex1);
}
return bcffile;
return file;
}

/// <summary>
/// Serializes to a bcfzip and saves it to disk
/// Serializes to a bcf and saves it to disk
/// </summary>
/// <param name="bcffile"></param>
/// <returns></returns>
Expand Down Expand Up @@ -448,18 +456,18 @@ private static bool SaveBcfFile(BcfFile bcffile)
}

/// <summary>
/// Prompts a the user to select where to save the bcfzip
/// Prompts a the user to select where to save the bcf
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
private static string SaveBcfDialog(string filename)
{
var saveFileDialog = new Microsoft.Win32.SaveFileDialog
{
Title = "Save as BCF report file (.bcfzip)",
Title = String.Format("Save as BCF file ({0})", FileExtension),
FileName = filename,
DefaultExt = ".bcfzip",
Filter = "BIM Collaboration Format (*.bcfzip)|*.bcfzip"
DefaultExt = FileExtension,
Filter = FileFilter
};

//if it goes fine I return the filename, otherwise empty
Expand Down
2 changes: 1 addition & 1 deletion Bcfier/UserControls/BcfierPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private void Window_DragOver(object sender, DragEventArgs e)
if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
{
var filenames = e.Data.GetData(DataFormats.FileDrop, true) as string[];
if (filenames.Any(x => Path.GetExtension(x).ToUpperInvariant() != ".BCFZIP"))
if (filenames.Any(x => Path.GetExtension(x).ToUpperInvariant() != BcfContainer.FileExtension.ToUpperInvariant()))
dropEnabled = false;
}
else
Expand Down