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

Added support for *.url files, closes #205 . #206

Merged
merged 4 commits into from
Jun 4, 2023
Merged
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
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;
ElektroKill marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}