Skip to content

Commit

Permalink
FileActionsManager v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ORelio committed Apr 18, 2018
0 parents commit 29c2a85
Show file tree
Hide file tree
Showing 18 changed files with 1,406 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.suo
Other
FileActionsConsole/bin
FileActionsConsole/obj
FileActionsConsole/*.user
FileActionsManager/bin
FileActionsManager/obj
FileActionsManager/*.user
.vs
58 changes: 58 additions & 0 deletions FileActionsConsole/FileActionsConsole.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9E2133B2-F1E4-4BDD-B105-1797C8F703F5}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileActionsConsole</RootNamespace>
<AssemblyName>FileActionsConsole</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShellFileType.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
67 changes: 67 additions & 0 deletions FileActionsConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using SharpTools;

namespace FileActionsConsole
{
/// <summary>
/// Command-line utility for creating/deleting file context menu actions
/// By ORelio - (c) 2015-2018 - Available under the CDDL-1.0 license
/// </summary>
class Program
{
static void Main(string[] args)
{
try
{
//ShellFileType.AddAction("txt", "testaction", "Testing FileActionsManager", "cmd.exe /C echo %1 && pause > nul");
//ShellFileType.RemoveAction("txt", "testaction");

if (args.Length == 3 && args[0] == "del")
{
ShellFileType.RemoveAction(args[1].Split(','), args[2]);
}
else if ((args.Length == 5 || args.Length == 6) && args[0] == "add")
{
ShellFileType.AddAction(args[1].Split(','), args[2], args[3], args[4], args.Length == 6 && args[5] == "default");
}
else
{
string exeName = Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);
Console.WriteLine(" - Windows Shell Menu Action Setter v1.0 - By ORelio -\n");
Console.WriteLine("Usage: " + exeName + " add <ext> <int> <dsp> <cmd> [def]");
Console.WriteLine("Usage: " + exeName + " del <ext> <int>\n");
Console.WriteLine("add : Add or update the action based on internal name");
Console.WriteLine("del : Remove the action based on internal name");
Console.WriteLine("ext : List of file extensions to affect eg mp3 or mp3,mp4 and so on");
Console.WriteLine("int : internal name to designate the action");
Console.WriteLine("dsp : display name of the shell menu item");
Console.WriteLine("cmd : command to execute when selecting item. File is provided as %1");
Console.WriteLine("def : add `default' as last argument for setting the action as the default one");
}
}
catch (UnauthorizedAccessException)
{
RelaunchAsAdmin(args, true);
}
}

public static void RelaunchAsAdmin(string[] args, bool waitforexit = false)
{
ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.Verb = "runas";
startInfo.Arguments = String.Join(" ", args.Select(arg => "\"" + args + '"').ToArray());
startInfo.FileName = Process.GetCurrentProcess().MainModule.FileName;

Process process = Process.Start(startInfo);

if (waitforexit)
process.WaitForExit();
}
}
}
36 changes: 36 additions & 0 deletions FileActionsConsole/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FileActionsManager")]
[assembly: AssemblyDescription("Manage shell menu items through command line")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("By ORelio - Microzoom.fr")]
[assembly: AssemblyProduct("File Actions Console")]
[assembly: AssemblyCopyright("Copyright © ORelio 2015-2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("edecdee5-b0d2-46a1-902d-7506c2610be7")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 29c2a85

Please sign in to comment.