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

Extract logic to DLL #21

Merged
merged 9 commits into from
Mar 1, 2014
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
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# We use this to keep .sh (like build.sh) with lf only line endings to keep bash from puking when it's edited on someone's windows box. See http://git-scm.com/docs/gitattributes#_checking-out_and_checking-in

*.sh eol=lf
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ before_install:

script:
- xbuild /p:TargetFrameworkProfile= ./src/ExplorerShortcutHelper/ExplorerShortcutHelper.csproj
- xbuild /p:TargetFrameworkProfile= ./src/LessMsi/LessMsi.csproj
- xbuild /p:TargetFrameworkProfile= ./src/LessMsi.Core/LessMsi.Core.csproj
- xbuild /p:TargetFrameworkProfile= ./src/LessMsi.Cli/LessMsi.Cli.csproj
- xbuild /p:TargetFrameworkProfile= ./src/LessMsi.Gui/LessMsi.Gui.csproj
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 12 additions & 8 deletions src/.build/lessmsi.msbuild
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

<ItemGroup>
<TheProjects Include="$(RootDir)\ExplorerShortcutHelper\ExplorerShortcutHelper.csproj"></TheProjects>
<TheProjects Include="$(RootDir)\LessMsi\LessMsi.csproj"></TheProjects>
<TheProjects Include="$(RootDir)\LessMsi.Core\LessMsi.Core.csproj"></TheProjects>
<TheProjects Include="$(RootDir)\LessMsi.Cli\LessMsi.Cli.csproj"></TheProjects>
<TheProjects Include="$(RootDir)\LessMsi.Gui\LessMsi.Gui.csproj"></TheProjects>
</ItemGroup>

<ItemGroup>
<DeployFiles Include="$(RootDir)\ExplorerShortcutHelper\bin\Release\AddWindowsExplorerShortcut.exe"></DeployFiles>
<DeployFiles Include="$(RootDir)\LessMsi\bin\Release\lessmsi.exe"></DeployFiles>
<DeployFiles Include="$(RootDir)\LessMsi\lib\libmspackn.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\LessMsi\lib\mspack.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\LessMsi\lib\wix.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\LessMsi\lib\wixcab.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\bin\Release\AddWindowsExplorerShortcut.exe"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\bin\Release\LessMsi.Core.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\bin\Release\LessMsi-cli.exe"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\bin\Release\LessMsi-gui.exe"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\lib\libmspackn.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\lib\mspack.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\lib\wix.dll"></DeployFiles>
<DeployFiles Include="$(RootDir)\..\lib\wixcab.dll"></DeployFiles>
</ItemGroup>

<Target Name="Init">
Expand Down Expand Up @@ -86,7 +90,7 @@

<MSBuild
Projects="%(TheProjects.FullPath)"
Properties="Configuration=Release;ApplicationVersion=$(TheVersion);SolutionDir=$(RootDir)"
Properties="Configuration=Release;Platform=x86;ApplicationVersion=$(TheVersion);SolutionDir=$(RootDir)"
Targets="Rebuild"
/>
</Target>
Expand Down
23 changes: 10 additions & 13 deletions src/ExplorerShortcutHelper/ExplorerShortcutHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{13F99803-59EF-4DEA-BE1C-68561A427B08}</ProjectGuid>
Expand Down Expand Up @@ -35,26 +35,23 @@
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>..\..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\CommonAssemblyInfo.cs">
Expand Down
18 changes: 0 additions & 18 deletions src/ExplorerShortcutHelper/ExplorerShortcutHelper.csproj.user

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using NDesk.Options;

namespace LessMsi
using System.Linq;
using NDesk.Options;
namespace LessMsi.Cli
{
internal class ExtractCommand : LessMsiCommand
{
Expand Down
71 changes: 71 additions & 0 deletions src/LessMsi.Cli/LessMsi.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{7ED32F80-2B7B-4F90-ADE9-22B8F3935C63}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LessMsi.Cli</RootNamespace>
<AssemblyName>lessmsi-cli</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<StartupObject>LessMsi.Cli.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="wix">
<HintPath>..\..\lib\wix.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ExtractCommand.cs" />
<Compile Include="LessMsiCommand.cs" />
<Compile Include="ListTableCommand.cs" />
<Compile Include="Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShowHelpCommand.cs" />
<Compile Include="ShowVersionCommand.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LessMsi.Core\LessMsi.Core.csproj">
<Project>{1fd916f2-1df6-42f6-9ad4-83565fbf8e5c}</Project>
<Name>LessMsi.Core</Name>
</ProjectReference>
</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>
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Text;

namespace LessMsi
using System.Collections.Generic;

namespace LessMsi.Cli
{
internal abstract class LessMsiCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using System.Linq;
using System.Text;
using LessMsi.Msi;
using Microsoft.Tools.WindowsInstallerXml.Msi;
using NDesk.Options;

namespace LessMsi
using Microsoft.Tools.WindowsInstallerXml.Msi;
using NDesk.Options;
namespace LessMsi.Cli
{
internal class ListTableCommand : LessMsiCommand
{
Expand Down
File renamed without changes.
74 changes: 12 additions & 62 deletions src/LessMsi/Program.cs → src/LessMsi.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,15 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using LessMsi.Msi;
using LessMsi.UI;
using NDesk.Options;

#endregion

namespace LessMsi
namespace LessMsi.Cli
{
public class Program
{
// defines for commandline output
[DllImport("kernel32.dll")]
static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;

enum ConsoleReturnCode
{
Success=0,
Expand All @@ -60,44 +49,32 @@ enum ConsoleReturnCode
[STAThread]
public static int Main(string[] args)
{
var doShowUI = args.Length == 0;
try
{
AttachConsole(ATTACH_PARENT_PROCESS);

/**
* See https://code.google.com/p/lessmsi/wiki/CommandLine for some use cases and docs on commandline parsing.
* See https://github.com/mono/mono/blob/master/mcs/tools/mdoc/Mono.Documentation/mdoc.cs#L54 for an example of using "commands" and "subcommands" with the NDesk.Options lib.
*/

var subcommands = new Dictionary<string, LessMsiCommand> {
{"o", new OpenGuiCommand()},
{"x", new ExtractCommand()},
{"/x", new ExtractCommand()},
{"l", new ListTableCommand()},
{"v", new ShowVersionCommand()},
{"h", new ShowHelpCommand()}
};

if (doShowUI)
{
LaunchForm("");
return (int) ConsoleReturnCode.Success;
}
else
{
LessMsiCommand cmd;
if (subcommands.TryGetValue(args[0], out cmd))
{
cmd.Run(new List<string>(args));
return (int) ConsoleReturnCode.Success;
}
else
{
ShowHelpCommand.ShowHelp("Unrecognized command");
return (int) ConsoleReturnCode.UnrecognizedCommand;
}
}
LessMsiCommand cmd;
if (args.Length > 0 && subcommands.TryGetValue(args[0], out cmd))
{
cmd.Run(new List<string>(args));
return (int)ConsoleReturnCode.Success;
}
else
{
ShowHelpCommand.ShowHelp("Unrecognized command");
return (int)ConsoleReturnCode.UnrecognizedCommand;
}
}
catch (NDesk.Options.OptionException oe)
{
Expand All @@ -110,24 +87,6 @@ public static int Main(string[] args)

return (int) ConsoleReturnCode.UnexpectedError;
}
finally
{
if (!doShowUI)
ConsoleNewLine();
}
}

private static void ConsoleNewLine()
{
try
{
// When using a winforms app with AttachConsole the app completes but there is no newline after the process stops. This gives the newline and looks normal from the console:
SendKeys.SendWait("{ENTER}");
}
catch (Exception e)
{
Debug.Fail(e.ToString());
}
}

/// <summary>
Expand Down Expand Up @@ -156,14 +115,5 @@ private static void EnsureFileRooted(ref string sFileName)
if (!Path.IsPathRooted(sFileName))
sFileName = Path.Combine(Directory.GetCurrentDirectory(), sFileName);
}

internal static int LaunchForm(string inputFile)
{
Application.EnableVisualStyles();
Application.DoEvents();// make sure EnableVisualStyles works.
MainForm form = new MainForm(inputFile);
Application.Run(form);
return 0;
}
}
}
29 changes: 29 additions & 0 deletions src/LessMsi.Cli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2004-2013 Scott Willeke (http://scott.willeke.com)
//
// Authors:
// Scott Willeke (scott@willeke.com)
//

using System.Reflection;

[assembly: AssemblyTitle("Less MSIérables (lessmsi) CLI interface")]
[assembly: AssemblyProduct("Less MSIérables (lessmsi)")]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace LessMsi
using System;
using System.Collections.Generic;
namespace LessMsi.Cli
{
internal class ShowHelpCommand : LessMsiCommand
{
Expand Down
Loading