mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-19 03:39:21 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace Editor;
|
|
|
|
internal class FileAssociations
|
|
{
|
|
/// <summary>
|
|
/// Creates/updates file associations between .sbproj files and the editor
|
|
/// </summary>
|
|
internal static void Create()
|
|
{
|
|
var sboxExeFilePath = $"\"{FileSystem.Root.GetFullPath( "sbox-dev.exe" )}\"";
|
|
|
|
try
|
|
{
|
|
RegistryKey fileTypeKey = Registry.CurrentUser.CreateSubKey( @"SOFTWARE\Classes\Sandbox.ProjectFile" );
|
|
fileTypeKey.SetValue( "", "Sandbox Project File" );
|
|
fileTypeKey.CreateSubKey( "DefaultIcon" ).SetValue( "", sboxExeFilePath );
|
|
|
|
RegistryKey shellKey = fileTypeKey.CreateSubKey( "shell" );
|
|
RegistryKey shellOpenKey = shellKey.CreateSubKey( "open" );
|
|
shellOpenKey.SetValue( "", "Open" );
|
|
shellOpenKey.CreateSubKey( "command" ).SetValue( "", sboxExeFilePath + " -project \"%1\"" );
|
|
|
|
RegistryKey fileExtensionKey = Registry.CurrentUser.CreateSubKey( @"SOFTWARE\Classes\.sbproj" );
|
|
fileExtensionKey.SetValue( "", "Sandbox.ProjectFile" );
|
|
|
|
// Tell explorer the file association has been changed
|
|
SHChangeNotify( 0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero );
|
|
}
|
|
catch ( Exception ex )
|
|
{
|
|
Log.Warning( ex, "Failed to associate project file extension" );
|
|
}
|
|
}
|
|
|
|
[DllImport( "shell32.dll", CharSet = CharSet.Auto, SetLastError = true )]
|
|
public static extern void SHChangeNotify( uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2 );
|
|
}
|