Skip to content

Commit

Permalink
Merge pull request #51 from ScottyMac52/featureFixSaveException
Browse files Browse the repository at this point in the history
1. Removed the Modify dialog
  • Loading branch information
ScottyMac52 authored Mar 27, 2019
2 parents df83fb1 + ed64276 commit 238c342
Show file tree
Hide file tree
Showing 18 changed files with 365 additions and 66 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,6 @@
/MFDSettingsManager/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache
/TestOutput
/Tests-MFDisplay/obj/Release
/CustomActions/bin/Debug
/CustomActions/obj/Debug
/Output
55 changes: 55 additions & 0 deletions CustomActions/CustomActions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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)' == '' ">AnyCPU</Platform>
<ProjectGuid>{957B51AC-5241-4213-9553-7623BD0AA2C6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CustomActions</RootNamespace>
<AssemblyName>CustomActions</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Output\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\Output\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SetUserPerms.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="SetUserPerms.Designer.cs">
<DependentUpon>SetUserPerms.cs</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
7 changes: 7 additions & 0 deletions CustomActions/CustomActions.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Program</StartAction>
<StartProgram>C:\Users\Scott\Source\Repos\MFDisplay\Deploy\setup.exe</StartProgram>
</PropertyGroup>
</Project>
36 changes: 36 additions & 0 deletions CustomActions/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("CustomActions")]
[assembly: AssemblyDescription("Defines custom install actions for the installer.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Vyper Industries")]
[assembly: AssemblyProduct("CustomActions")]
[assembly: AssemblyCopyright("Copyright © 2019 Vyper Industires")]
[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("957b51ac-5241-4213-9553-7623bd0aa2c6")]

// 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")]
36 changes: 36 additions & 0 deletions CustomActions/SetUserPerms.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions CustomActions/SetUserPerms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.IO;
using System.Security.AccessControl;
using System.Security.Permissions;
using System.Security.Principal;

namespace CustomActions
{
[RunInstaller(true)]
public partial class SetUserPerms : Installer
{
public SetUserPerms()
{
InitializeComponent();
}

[SecurityPermission(SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);

// This gets the named parameters passed in from your custom action
string folder = Context.Parameters["folder"];

var powerUserSid = new SecurityIdentifier(WellKnownSidType.BuiltinPowerUsersSid, null);
var userSid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
var creatorOwnerSid = new SecurityIdentifier(WellKnownSidType.CreatorOwnerSid, null);

// This gets the built in users group
File.AppendAllText(Path.Combine(folder, "customactions.log"), $"{Environment.NewLine}{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()} : This is output from the installer, Creator: {creatorOwnerSid?.Value} PowerUser: {powerUserSid} User: {userSid} the folder: {folder}{Environment.NewLine}");
var writerulePowerUsers = new FileSystemAccessRule(powerUserSid, FileSystemRights.FullControl, AccessControlType.Allow);
var writeruleUsers = new FileSystemAccessRule(userSid, FileSystemRights.FullControl, AccessControlType.Allow);
var writeruleCreator = new FileSystemAccessRule(creatorOwnerSid, FileSystemRights.FullControl, AccessControlType.Allow);

if (!string.IsNullOrEmpty(folder) && Directory.Exists(folder))
{
// Get your file's ACL
DirectorySecurity fsecurity = Directory.GetAccessControl(folder);

// Add the new rule to the ACL
fsecurity.AddAccessRule(writerulePowerUsers);
fsecurity.AddAccessRule(writeruleUsers);
fsecurity.AddAccessRule(writeruleCreator);

// Set the ACL back to the file
Directory.SetAccessControl(folder, fsecurity);

File.AppendAllText(Path.Combine(folder, "customactions.log"), $"{Environment.NewLine}{DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()} : folder: {folder} was processed.{Environment.NewLine}");
}

}

[SecurityPermission(SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
var site = Context.Parameters["site"] ?? "https://github.com/ScottyMac52/MFDisplay/wiki";
System.Diagnostics.Process.Start(site);
}
}
}
9 changes: 9 additions & 0 deletions MFDSettingsManager/Models/ConfigurationDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ public string ToReadableString()
return $"Config {Name} for {ModuleName} at ({Left}, {Top}) for ({Width}, {Height}) with Opacity {Opacity} from {completePath ?? "Unknown Image"} was {fileStatus} at Offset ({XOffsetStart}, {YOffsetStart}) for ({XOffsetFinish - XOffsetStart}, {YOffsetFinish - YOffsetStart}).";
}

/// <summary>
/// Short form
/// </summary>
/// <returns></returns>
public override string ToString()
{
return ToReadableString();
}

#endregion Public methods

#region Private helpers
Expand Down
4 changes: 2 additions & 2 deletions MFDSettingsManager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// 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("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
[assembly: AssemblyVersion("2.4.0.0")]
[assembly: AssemblyFileVersion("2.4.0.0")]
20 changes: 20 additions & 0 deletions MFDisplay.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MFDSettingsManager", "MFDSe
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup", "Setup\Setup.vdproj", "{02517BB3-3B9C-4574-A934-2C05A6A29928}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomActions", "CustomActions\CustomActions.csproj", "{957B51AC-5241-4213-9553-7623BD0AA2C6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
All|Any CPU = All|Any CPU
Expand Down Expand Up @@ -95,6 +97,24 @@ Global
{02517BB3-3B9C-4574-A934-2C05A6A29928}.Release|Any CPU.Build.0 = Release
{02517BB3-3B9C-4574-A934-2C05A6A29928}.Release|x64.ActiveCfg = Release
{02517BB3-3B9C-4574-A934-2C05A6A29928}.Release|x86.ActiveCfg = Release
{957B51AC-5241-4213-9553-7623BD0AA2C6}.All|Any CPU.ActiveCfg = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.All|Any CPU.Build.0 = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.All|x64.ActiveCfg = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.All|x64.Build.0 = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.All|x86.ActiveCfg = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.All|x86.Build.0 = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Debug|x64.ActiveCfg = Debug|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Debug|x64.Build.0 = Debug|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Debug|x86.ActiveCfg = Debug|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Debug|x86.Build.0 = Debug|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Release|Any CPU.Build.0 = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Release|x64.ActiveCfg = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Release|x64.Build.0 = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Release|x86.ActiveCfg = Release|Any CPU
{957B51AC-5241-4213-9553-7623BD0AA2C6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 9 additions & 2 deletions MFDisplay/ConfigurationWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using MFDSettingsManager.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -145,8 +146,14 @@ private void Save()
savedConfig.DefaultConfig = cbDefaultModule.SelectedValue?.ToString();
Logger.Info($"Saving the configuration file {savedConfig.CurrentConfiguration.FilePath}...");
// TODO: Update the Configuration Section from the Model

savedConfig.CurrentConfiguration.Save();
try
{
savedConfig.CurrentConfiguration.Save(ConfigurationSaveMode.Modified, true);
}
catch (System.Exception ex)
{
Logger.Error($"Unable to save the configuration to {savedConfig.CurrentConfiguration.FilePath}", ex);
}
}

private void ConfigurationMenuItem_Click(object sender, RoutedEventArgs e)
Expand Down
17 changes: 6 additions & 11 deletions MFDisplay/MFDisplay.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="ConfigurationWindow.xaml.cs">
<DependentUpon>ConfigurationWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Extenisons\ExtensionsForWPF.cs" />
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
Expand All @@ -264,11 +261,8 @@
<DependentUpon>MFDisplayApp.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ModuleDefinitionComparer.cs" />
<Compile Include="SingleInstance.cs" />
<Page Include="ConfigurationWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="MainWindow.xaml">
<SubType>Designer</SubType>
<Generator>XamlIntelliSenseFileGenerator</Generator>
Expand Down Expand Up @@ -308,12 +302,13 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="log4net.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="MFDisplay_TemporaryKey.pfx" />
<Content Include="mfdsettings.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config">
<SubType>Designer</SubType>
Expand All @@ -324,10 +319,10 @@
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<Content Include="App.config">
<SubType>Designer</SubType>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
Expand Down
26 changes: 5 additions & 21 deletions MFDisplay/MFDisplayApp.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,12 @@ protected override void OnStartup(StartupEventArgs e)
}

Configuration = sectionConfig.ToModel(Logger);
while (!Directory.Exists(Configuration?.FilePath))
{
var configWindow = new ConfigurationWindow()
{
Logger = Logger
};
configWindow.ShowInTaskbar = true;
configWindow.ShowDialog();
sectionConfig = MFDConfigurationSection.GetConfig(Logger);
Configuration = sectionConfig.ToModel(Logger);
if (!Directory.Exists(Configuration?.FilePath))
{
var msgResult = MessageBox.Show($"{Configuration?.FilePath} is not a valid path. Do you wish to try another path?", "Invalid Path Configuration", MessageBoxButton.YesNo, MessageBoxImage.Hand);
if(msgResult != MessageBoxResult.Yes)
{
break;
}
}
}

if (!Directory.Exists(Configuration?.FilePath))
if(!Directory.Exists(Configuration?.FilePath))
{
var mfdSettingsFile = Path.Combine((new FileInfo(assmLocation))?.DirectoryName, "mfdsettings.config");
var errorMessage = $"{Configuration.FilePath} is not a valid path. Please use an elevated editor, runas Administrator, and edit the FilePath in the file {mfdSettingsFile}";
Logger.Error(errorMessage);
MessageBox.Show(errorMessage, "Configuration Error", MessageBoxButton.OK, MessageBoxImage.Error);
Shutdown(2);
}
else
Expand Down
3 changes: 0 additions & 3 deletions MFDisplay/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<MenuItem Header="_File">
<MenuItem Header="_Exit" CommandParameter="Exit" Click="FileMenuItem_Click" />
</MenuItem>
<MenuItem Header="_Configuration">
<MenuItem Header="_Modify" CommandParameter="Modify" Click="ConfigurationMenuItem_Click"/>
</MenuItem>
<MenuItem Header="_Help">
<MenuItem Header="_About" CommandParameter="About" Click="HelpMenuItem_Click"/>
</MenuItem>
Expand Down
Loading

0 comments on commit 238c342

Please sign in to comment.