Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.17 #1026

Merged
merged 2 commits into from
Oct 23, 2023
Merged

1.17 #1026

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
28 changes: 25 additions & 3 deletions src/RhinoInside.Revit.External/Extensions/System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ public static string TripleDot(this string sourceString, int maxLength)
sourceString.Substring(0, maxLength - 1) + '…' :
sourceString;
}
}
}

namespace System.IO
{
static class PathExtension
{
public static bool IsFullyQualifiedPath(this string path)
{
if (path == null) return false;
if (path.Length < 2) return false;
if (IsDirectorySeparator(path[0]))
return path[1] == '?' || IsDirectorySeparator(path[1]);

return
(
(path.Length >= 3) &&
(path[1] == Path.VolumeSeparatorChar) &&
IsDirectorySeparator(path[2]) &&
IsValidDriveChar(path[0])
);

bool IsValidDriveChar(char value) => ('A' <= value && value <= 'Z') || ('a' <= value && value <= 'z');
bool IsDirectorySeparator(char c) => c == Path.DirectorySeparatorChar || c == Path.AltDirectorySeparatorChar;
}

[DllImport("SHLWAPI", CharSet = CharSet.Unicode)]
static extern bool PathCompactPathExW([Out] Text.StringBuilder pszOut, string szPath, int cchMax, int dwFlags);
Expand All @@ -87,10 +112,7 @@ internal static string TripleDotPath(this string path, int maxLength)
return builder.ToString();
}
}
}

namespace System.IO
{
internal static class FileInfoExtension
{
public static void MoveTo(this FileInfo source, string destFileName, bool overwrite)
Expand Down
3 changes: 1 addition & 2 deletions src/RhinoInside.Revit.External/Settings/AddIns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public class RevitAddIns : List<AddIn>

public FileInfo ToFileInfo(string path)
{
path = path.Trim(Path.DirectorySeparatorChar);
if (!Path.IsPathRooted(path))
if (!path.IsFullyQualifiedPath())
path = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(ManifestPath), path));

return new FileInfo(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
if (filePath.Last() == Path.DirectorySeparatorChar)
filePath = Path.Combine(filePath, doc.Title);

if (Path.IsPathRooted(filePath) && filePath.Contains(Path.DirectorySeparatorChar))
if (filePath.IsFullyQualifiedPath())
{
if (!Path.HasExtension(filePath))
{
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Components/Family/New.cs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ static string GetDefaultTemplatePath(ARDB.Document doc, ARDB.ElementId categoryI

static bool FindTemplatePath(ARDB.Document doc, ref string templatePath, out bool pathWasRelative)
{
pathWasRelative = !Path.IsPathRooted(templatePath);
pathWasRelative = !templatePath.IsFullyQualifiedPath();

// Validate input
foreach (var invalid in Path.GetInvalidPathChars())
Expand Down
2 changes: 1 addition & 1 deletion src/RhinoInside.Revit.GH/Components/Family/Save.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
if (!Path.HasExtension(filePath))
filePath += ".rfa";

if (!Path.IsPathRooted(filePath))
if (!filePath.IsFullyQualifiedPath())
{
filePath = Path.Combine(Types.Document.FromValue(family.Document).SwapFolder.Directory.FullName, "Families", filePath);
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
Expand Down
4 changes: 2 additions & 2 deletions src/RhinoInside.Revit.GH/Components/Sheets/SheetRevisions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ protected override void TrySolveInstance(IGH_DataAccess DA)
if (update)
{
StartTransaction(sheet.Document);
sheet.Value.SetAdditionalRevisionIds(revisions.Select(x => x.Id).ToArray());
sheet.Value.SetAdditionalRevisionIds(revisions.OfType<Types.Revision>().Select(x => x.Id).ToArray());
sheet.Document.Regenerate();
}

Params.TrySetData(DA, "Current Revision", () => Types.Element.FromElementId(sheet.Document, sheet.Value.GetCurrentRevision()));
Params.TrySetData(DA, "Current Revision", () => Types.Element.FromElementId(sheet.Document, sheet.Value.GetCurrentRevision()) as Types.Revision);
Params.TrySetDataList(DA, "Revisions on Sheet", () => sheet.Value.GetAdditionalRevisionIds().Select(x => Types.Element.FromElementId(sheet.Document, x)));
Params.TrySetDataList(DA, "Scheduled Revisions", () => sheet.Value.GetAllRevisionIds().Select(x => Types.Element.FromElementId(sheet.Document, x)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/RhinoInside.Revit.GH/Components/Views/ExportImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ protected override void TrySolveInstance(IGH_DataAccess DA)

if (!Params.TryGetData(DA, "Folder", out string folder)) return;
{
if (folder is object && folder.Any(x => Path.GetInvalidPathChars().Contains(x)))
if (folder?.Any(x => Path.GetInvalidPathChars().Contains(x)) is true)
throw new Exceptions.RuntimeArgumentException("Folder", $"'{folder}' is not a valid folder name", folder);

if (folder is object && !Path.IsPathRooted(folder))
if (folder?.IsFullyQualifiedPath() is false)
throw new Exceptions.RuntimeArgumentException("Folder", $"'{folder}' is not a valid absolute path", folder);
}

Expand Down
1 change: 1 addition & 0 deletions src/RhinoInside.Revit.GH/Parameters/Document.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
namespace RhinoInside.Revit.Convert.Render
{
using Numerical;
using Convert.Geometry;
using Convert.System.Drawing;
using Convert.Units;
using External.DB.Extensions;
using RhinoInside.Revit.Convert.Geometry;
using DBXS = External.DB.Schemas;

/// <summary>
Expand Down Expand Up @@ -294,7 +294,7 @@ static SimulatedProceduralTexture GetUnifiedBitmapSchemaTexture(Asset asset)
{
try
{
if (Path.IsPathRooted(entry) ?
if (entry.IsFullyQualifiedPath() ?
File.Exists(entry) :
Rhino.ApplicationSettings.FileSettings.FindFile(entry) is string)
{
Expand Down Expand Up @@ -370,7 +370,7 @@ static SimulatedProceduralTexture GetBumpMapSchemaTexture(Asset asset)
{
try
{
if (Path.IsPathRooted(entry) ?
if (entry.IsFullyQualifiedPath() ?
File.Exists(entry) :
Rhino.ApplicationSettings.FileSettings.FindFile(entry) is string)
{
Expand Down