Skip to content

Commit

Permalink
Added support for *.url files, closes #205 . (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore authored Jun 4, 2023
1 parent e983c55 commit ede8cb0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_namespace_declarations = block_scoped:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
Expand Down
17 changes: 17 additions & 0 deletions dnSpy/dnSpy/Documents/TreeView/DocumentTreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ void OnDropFiles(int index, string[] filenames) {
filenames = GetFiles(filenames);

ResolveWindowsShortcutFiles(filenames);
ResolveInternetShortcutFiles(filenames);

var origFilenames = filenames;
var documents = DocumentService.GetDocuments();
Expand Down Expand Up @@ -844,6 +845,22 @@ static void ResolveWindowsShortcutFiles(string[] filenames) {
}
}

static void ResolveInternetShortcutFiles(string[] filenames) {
for (var i = 0; i < filenames.Length; i++) {
var filename = filenames[i];
if (!filename.EndsWith(".url", StringComparison.OrdinalIgnoreCase))
continue;
if (!File.Exists(filename))
continue;
var urlString = InternetShortcutFileFormat.GetUrlFromInternetShortcutFile(filename);
if (!Uri.TryCreate(urlString, UriKind.Absolute, out var urlUri))
continue;
if (!urlUri.IsFile)
continue;
filenames[i] = urlUri.AbsolutePath;
}
}

static string[] GetFiles(string[] filenames) {
var result = new List<string>(filenames.Length);
foreach (var filename in filenames) {
Expand Down
34 changes: 34 additions & 0 deletions dnSpy/dnSpy/Documents/TreeView/InternetShortcutFileFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright (C) 2023 ElektroKill
This file is part of dnSpy
dnSpy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
dnSpy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with dnSpy. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Runtime.InteropServices;
using System.Text;

namespace dnSpy.Documents.TreeView {
static class InternetShortcutFileFormat {
internal static string? GetUrlFromInternetShortcutFile(string filename) {
var urlValue = new StringBuilder(255);
int charsCopied = GetPrivateProfileString("InternetShortcut", "URL", "", urlValue, 255, filename);
return charsCopied < 1 ? null : urlValue.ToString();
}

[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize, string lpFileName);
}
}

0 comments on commit ede8cb0

Please sign in to comment.