Skip to content

Commit 0f85f68

Browse files
committed
Make ShellLinkFile publicly accessible for callers.
1 parent 32fedf9 commit 0f85f68

2 files changed

Lines changed: 116 additions & 10 deletions

File tree

src/PSADT/PSADT.Interop/STGM.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
3+
namespace PSADT.Interop
4+
{
5+
/// <summary>
6+
/// The STGM constants are flags that indicate conditions for creating and deleting the object and access modes for the object. The STGM constants are included in the IStorage, IStream, and IPropertySetStorage interfaces and in the StgCreateDocfile, StgCreateStorageEx, StgCreateDocfileOnILockBytes, StgOpenStorage, and StgOpenStorageEx functions.
7+
/// </summary>
8+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1008:Enums should have zero value", Justification = "There's no zero value for this in the Win32 API.")]
9+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1028:Enum Storage should be Int32", Justification = "The underlying type is uint to match the Win32 API.")]
10+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "These duplications are already within the Win32 API.")]
11+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Matches the Win32 API naming.")]
12+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1712:Do not prefix enum values with type name", Justification = "Matches the Win32 API naming.")]
13+
[Flags]
14+
public enum STGM : uint
15+
{
16+
/// <summary>
17+
/// Indicates that, in direct mode, each change to a storage or stream element is written as it occurs. This is the default if neither STGM_DIRECT nor STGM_TRANSACTED is specified.
18+
/// </summary>
19+
STGM_DIRECT = Windows.Win32.System.Com.STGM.STGM_DIRECT,
20+
21+
/// <summary>
22+
/// Indicates that, in transacted mode, changes are buffered and written only if an explicit commit operation is called. To ignore the changes, call the Revert method in the IStream, IStorage, or IPropertyStorage interface. The COM compound file implementation of IStorage does not support transacted streams, which means that streams can be opened only in direct mode, and you cannot revert changes to them, however transacted storages are supported. The compound file, stand-alone, and NTFS file system implementations of IPropertySetStorage similarly do not support transacted, simple property sets because these property sets are stored in streams. However, transactioning of nonsimple property sets, which can be created by specifying the PROPSETFLAG_NONSIMPLE flag in the grfFlags parameter of IPropertySetStorage::Create, are supported.
23+
/// </summary>
24+
STGM_TRANSACTED = Windows.Win32.System.Com.STGM.STGM_TRANSACTED,
25+
26+
/// <summary>
27+
/// Provides a faster implementation of a compound file in a limited, but frequently used, case. For more information, see the Remarks section.
28+
/// </summary>
29+
STGM_SIMPLE = Windows.Win32.System.Com.STGM.STGM_SIMPLE,
30+
31+
/// <summary>
32+
/// Indicates that the object is read-only, meaning that modifications cannot be made. For example, if a stream object is opened with STGM_READ, the ISequentialStream::Read method may be called, but the ISequentialStream::Write method may not. Similarly, if a storage object opened with STGM_READ, the IStorage::OpenStream and IStorage::OpenStorage methods may be called, but the IStorage::CreateStream and IStorage::CreateStorage methods may not.
33+
/// </summary>
34+
STGM_READ = Windows.Win32.System.Com.STGM.STGM_READ,
35+
36+
/// <summary>
37+
/// Enables you to save changes to the object, but does not permit access to its data. The provided implementations of the IPropertyStorage and IPropertySetStorage interfaces do not support this write-only mode.
38+
/// </summary>
39+
STGM_WRITE = Windows.Win32.System.Com.STGM.STGM_WRITE,
40+
41+
/// <summary>
42+
/// Enables access and modification of object data. For example, if a stream object is created or opened in this mode, it is possible to call both IStream::Read and IStream::Write. Be aware that this constant is not a simple binary OR operation of the STGM_WRITE and STGM_READ elements.
43+
/// </summary>
44+
STGM_READWRITE = Windows.Win32.System.Com.STGM.STGM_READWRITE,
45+
46+
/// <summary>
47+
/// Specifies that subsequent openings of the object are not denied read or write access. If no flag from the sharing group is specified, this flag is assumed.
48+
/// </summary>
49+
STGM_SHARE_DENY_NONE = Windows.Win32.System.Com.STGM.STGM_SHARE_DENY_NONE,
50+
51+
/// <summary>
52+
/// Prevents others from subsequently opening the object in STGM_READ mode. It is typically used on a root storage object.
53+
/// </summary>
54+
STGM_SHARE_DENY_READ = Windows.Win32.System.Com.STGM.STGM_SHARE_DENY_READ,
55+
56+
/// <summary>
57+
/// Prevents others from subsequently opening the object for STGM_WRITE or STGM_READWRITE access. In transacted mode, sharing of STGM_SHARE_DENY_WRITE or STGM_SHARE_EXCLUSIVE can significantly improve performance because they do not require snapshots. For more information about transactioning, see the Remarks section.
58+
/// </summary>
59+
STGM_SHARE_DENY_WRITE = Windows.Win32.System.Com.STGM.STGM_SHARE_DENY_WRITE,
60+
61+
/// <summary>
62+
/// Prevents others from subsequently opening the object in any mode. Be aware that this value is not a simple bitwise OR operation of the STGM_SHARE_DENY_READ and STGM_SHARE_DENY_WRITE values. In transacted mode, sharing of STGM_SHARE_DENY_WRITE or STGM_SHARE_EXCLUSIVE can significantly improve performance because they do not require snapshots. For more information about transactioning, see the Remarks section.
63+
/// </summary>
64+
STGM_SHARE_EXCLUSIVE = Windows.Win32.System.Com.STGM.STGM_SHARE_EXCLUSIVE,
65+
66+
/// <summary>
67+
/// Opens the storage object with exclusive access to the most recently committed version. Thus, other users cannot commit changes to the object while you have it open in priority mode. You gain performance benefits for copy operations, but you prevent others from committing changes. Limit the time that objects are open in priority mode. You must specify STGM_DIRECT and STGM_READ with priority mode, and you cannot specify STGM_DELETEONRELEASE. STGM_DELETEONRELEASE is only valid when creating a root object, such as with StgCreateStorageEx. It is not valid when opening an existing root object, such as with StgOpenStorageEx. It is also not valid when creating or opening a subelement, such as with IStorage::OpenStorage.
68+
/// </summary>
69+
STGM_PRIORITY = Windows.Win32.System.Com.STGM.STGM_PRIORITY,
70+
71+
/// <summary>
72+
/// Indicates that the underlying file is to be automatically destroyed when the root storage object is released. This feature is most useful for creating temporary files. This flag can only be used when creating a root object, such as with StgCreateStorageEx. It is not valid when opening a root object, such as with StgOpenStorageEx, or when creating or opening a subelement, such as with IStorage::CreateStream. It is also not valid to use this flag and the STGM_CONVERT flag simultaneously.
73+
/// </summary>
74+
STGM_DELETEONRELEASE = Windows.Win32.System.Com.STGM.STGM_DELETEONRELEASE,
75+
76+
/// <summary>
77+
/// Indicates that, in transacted mode, a temporary scratch file is usually used to save modifications until the Commit method is called. Specifying STGM_NOSCRATCH permits the unused portion of the original file to be used as work space instead of creating a new file for that purpose. This does not affect the data in the original file, and in certain cases can result in improved performance. It is not valid to specify this flag without also specifying STGM_TRANSACTED, and this flag may only be used in a root open. For more information about NoScratch mode, see the Remarks section.
78+
/// </summary>
79+
STGM_NOSCRATCH = Windows.Win32.System.Com.STGM.STGM_NOSCRATCH,
80+
81+
/// <summary>
82+
/// Indicates that an existing storage object or stream should be removed before the new object replaces it. A new object is created when this flag is specified only if the existing object has been successfully removed.
83+
/// </summary>
84+
STGM_CREATE = Windows.Win32.System.Com.STGM.STGM_CREATE,
85+
86+
/// <summary>
87+
/// Creates the new object while preserving existing data in a stream named "Contents". In the case of a storage object or a byte array, the old data is formatted into a stream regardless of whether the existing file or byte array currently contains a layered storage object. This flag can only be used when creating a root storage object. It cannot be used within a storage object; for example, in IStorage::CreateStream. It is also not valid to use this flag and the STGM_DELETEONRELEASE flag simultaneously.
88+
/// </summary>
89+
STGM_CONVERT = Windows.Win32.System.Com.STGM.STGM_CONVERT,
90+
91+
/// <summary>
92+
/// Causes the create operation to fail if an existing object with the specified name exists. In this case, STG_E_FILEALREADYEXISTS is returned. This is the default creation mode; that is, if no other create flag is specified, STGM_FAILIFTHERE is implied.
93+
/// </summary>
94+
STGM_FAILIFTHERE = Windows.Win32.System.Com.STGM.STGM_FAILIFTHERE,
95+
96+
/// <summary>
97+
/// This flag is used when opening a storage object with STGM_TRANSACTED and without STGM_SHARE_EXCLUSIVE or STGM_SHARE_DENY_WRITE. In this case, specifying STGM_NOSNAPSHOT prevents the system-provided implementation from creating a snapshot copy of the file. Instead, changes to the file are written to the end of the file. Unused space is not reclaimed unless consolidation is performed during the commit, and there is only one current writer on the file. When the file is opened in no snapshot mode, another open operation cannot be performed without specifying STGM_NOSNAPSHOT. This flag may only be used in a root open operation. For more information about NoSnapshot mode, see the Remarks section.
98+
/// </summary>
99+
STGM_NOSNAPSHOT = Windows.Win32.System.Com.STGM.STGM_NOSNAPSHOT,
100+
101+
/// <summary>
102+
/// Supports direct mode for single-writer, multireader file operations. For more information, see the Remarks section.
103+
/// </summary>
104+
STGM_DIRECT_SWMR = Windows.Win32.System.Com.STGM.STGM_DIRECT_SWMR,
105+
}
106+
}

src/PSADT/PSADT/ShortcutManagement/ShellLinkFile.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace PSADT.ShortcutManagement
2424
/// and <c>IPropertyStore</c> COM interfaces to provide full access to shell link properties,
2525
/// flags, and extended properties such as AppUserModelID.
2626
/// </remarks>
27-
internal sealed class ShellLinkFile : IDisposable
27+
public sealed class ShellLinkFile : IDisposable
2828
{
2929
/// <summary>
3030
/// Creates a new, empty shell link.
@@ -56,11 +56,11 @@ public static ShellLinkFile New(string targetPath)
5656
/// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is empty or whitespace.</exception>
5757
/// <exception cref="FileNotFoundException">Thrown when the specified file does not exist.</exception>
5858
/// <exception cref="COMException">Thrown when the COM operation fails.</exception>
59-
/// <remarks>Use <see cref="Load(string, STGM)"/> with <see cref="STGM.STGM_READWRITE"/> if you need to modify the shortcut.</remarks>
59+
/// <remarks>Use <see cref="Load(string, Interop.STGM)"/> with <see cref="Interop.STGM.STGM_READWRITE"/> if you need to modify the shortcut.</remarks>
6060
[MethodImpl(MethodImplOptions.AggressiveInlining)]
6161
public static ShellLinkFile Load(string filePath)
6262
{
63-
return Load(filePath, STGM.STGM_READ);
63+
return Load(filePath, Interop.STGM.STGM_READ);
6464
}
6565

6666
/// <summary>
@@ -73,7 +73,7 @@ public static ShellLinkFile Load(string filePath)
7373
/// <exception cref="ArgumentException">Thrown when <paramref name="filePath"/> is empty or whitespace.</exception>
7474
/// <exception cref="FileNotFoundException">Thrown when the specified file does not exist.</exception>
7575
/// <exception cref="COMException">Thrown when the COM operation fails.</exception>
76-
public static ShellLinkFile Load(string filePath, STGM storageMode)
76+
public static ShellLinkFile Load(string filePath, Interop.STGM storageMode)
7777
{
7878
ArgumentException.ThrowIfNullOrWhiteSpace(filePath);
7979
if (!File.Exists(filePath))
@@ -83,7 +83,7 @@ public static ShellLinkFile Load(string filePath, STGM storageMode)
8383
ShellLinkFile shellLink = new();
8484
try
8585
{
86-
((IPersistFile)shellLink._shellLink).Load(filePath, storageMode);
86+
((IPersistFile)shellLink._shellLink).Load(filePath, (STGM)storageMode);
8787
return shellLink;
8888
}
8989
catch
@@ -266,18 +266,18 @@ public ushort Hotkey
266266
/// </summary>
267267
/// <value>The <see cref="SHOW_WINDOW_CMD"/> value indicating how the window should be shown.</value>
268268
/// <exception cref="COMException">Thrown when the COM operation fails.</exception>
269-
public SHOW_WINDOW_CMD WindowStyle
269+
public Interop.SHOW_WINDOW_CMD WindowStyle
270270
{
271271
get
272272
{
273273
ObjectDisposedException.ThrowIf(_disposed, this);
274274
_shellLink.GetShowCmd(out SHOW_WINDOW_CMD showCmd);
275-
return showCmd;
275+
return (Interop.SHOW_WINDOW_CMD)showCmd;
276276
}
277277
set
278278
{
279279
ObjectDisposedException.ThrowIf(_disposed, this);
280-
_shellLink.SetShowCmd(value);
280+
_shellLink.SetShowCmd((SHOW_WINDOW_CMD)value);
281281
}
282282
}
283283

@@ -710,10 +710,10 @@ public void SetRelativePath(string relativePath)
710710
/// <param name="hwnd">A handle to the parent window for any UI that may be displayed.</param>
711711
/// <param name="flags">Flags that control the resolution process.</param>
712712
/// <exception cref="COMException">Thrown when the COM operation fails.</exception>
713-
public void Resolve(HWND hwnd, uint flags)
713+
public void Resolve(nint hwnd, uint flags)
714714
{
715715
ObjectDisposedException.ThrowIf(_disposed, this);
716-
_shellLink.Resolve(hwnd, flags);
716+
_shellLink.Resolve((HWND)hwnd, flags);
717717
}
718718

719719
/// <summary>

0 commit comments

Comments
 (0)