Skip to content

Commit

Permalink
Merge branch 'lnk-files'
Browse files Browse the repository at this point in the history
- if a part of an include path is a windows shortcut, this is resolved and can be processed
  • Loading branch information
Waldemar Porscha committed May 17, 2024
2 parents 116e1a9 + 1bb3f5f commit d884b90
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
6 changes: 3 additions & 3 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

[assembly: System.Reflection.AssemblyCompanyAttribute("OpenKNX")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("3.2.7.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("3.2.7")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("3.3.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("3.3.0")]
[assembly: System.Reflection.AssemblyProductAttribute("OpenKNXproducer")]
[assembly: System.Reflection.AssemblyTitleAttribute("OpenKNXproducer")]
[assembly: System.Reflection.AssemblyVersionAttribute("3.2.7.0")]
[assembly: System.Reflection.AssemblyVersionAttribute("3.3.0.0")]
1 change: 1 addition & 0 deletions OpenKNXproducer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
<!-- <PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" /> -->
</ItemGroup>
<ItemGroup>
Expand Down
47 changes: 47 additions & 0 deletions PathHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Text;

namespace OpenKNXproducer
{
public static class PathHelper
{
// Resolve windows shortuct .lnk file target
static string GetLnkTargetPath(string iFilepath)
{
var lLink = WindowsShortcutFactory.WindowsShortcut.Load(iFilepath);
return Path.Combine(lLink.WorkingDirectory, lLink.Path);
}

// Build full path and resolve .lnk files in the path specification
public static string BuildFullPath(string iCurrentDir, string iPath)
{
string lCurrentDir = Path.IsPathFullyQualified(iCurrentDir) ? iCurrentDir : Path.Combine(Directory.GetCurrentDirectory(), iCurrentDir);
var lAbsolutePath = Path.GetFullPath(Path.Combine(lCurrentDir, iPath));
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
return lAbsolutePath;
// Windows only: check path and resolve .lnk file links
var lDir = new StringBuilder(Path.GetPathRoot(lAbsolutePath));
var lParts = lAbsolutePath.Substring(lDir.Length).Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar } );
for (int i = 0; i < lParts.Length - 1; i++)
{
lDir.Append(lParts[i]);
string lPathToCurrentSegment = lDir.ToString();
if (!Directory.Exists(lPathToCurrentSegment))
{
// Check if shortcut file .lnk exist on the path
string lLinkFile = lPathToCurrentSegment + ".lnk";
if (File.Exists(lLinkFile))
{
var lDirectoryOfLink = Path.GetDirectoryName(lPathToCurrentSegment);
string lTargetDir = Path.Combine(lDirectoryOfLink, GetLnkTargetPath(lLinkFile));
string lFullPath = lTargetDir + Path.DirectorySeparatorChar + string.Join(Path.DirectorySeparatorChar, lParts.Skip(i + 1));
return lFullPath;
}
// part of path not found, us as it is
return lAbsolutePath;
}
lDir.Append(Path.DirectorySeparatorChar);
}
return lAbsolutePath;
}
}
}
9 changes: 5 additions & 4 deletions ProcessInclude.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1432,14 +1432,14 @@ public bool IsIconId(string iId)

public string BaggagesName { get { return mBaggagesName; } }
public string CurrentDir { get { return mCurrentDir; } }


private bool VerifyModuleDependency(DefineContent iDefine, string iCurrentDir)
{
bool lResult = true;
if (iDefine.VerifyFile != "")
{
string lFileName = Path.Combine(iCurrentDir, iDefine.VerifyFile);
string lFileName = PathHelper.BuildFullPath(iCurrentDir, iDefine.VerifyFile);
string lVersion = "-1";
int lVersionInt = -1;
try
Expand Down Expand Up @@ -1502,9 +1502,10 @@ public bool LoadAdvanced(string iFileName)
bool lIsNew = false;
if (!mLoaded)
{
string lCurrentDir = Path.GetDirectoryName(Path.GetFullPath(iFileName));
string labsoluteFilePath = PathHelper.BuildFullPath(Directory.GetCurrentDirectory(), iFileName);;
string lCurrentDir = Path.GetDirectoryName(labsoluteFilePath);
mCurrentDir = lCurrentDir;
string lFileData = File.ReadAllText(iFileName);
string lFileData = File.ReadAllText(labsoluteFilePath);
lFileData = ReplaceXmlns(lFileData);
mLoaded = true;
lIsNew = true;
Expand Down

0 comments on commit d884b90

Please sign in to comment.