Skip to content

Commit

Permalink
Merge pull request #1026 from mcneel/1.17
Browse files Browse the repository at this point in the history
1.17
  • Loading branch information
kike-garbo authored Oct 23, 2023
2 parents 3412b59 + a636d5c commit e0e7819
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 15 deletions.
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

0 comments on commit e0e7819

Please sign in to comment.