mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Installer works, but there are a few issues with it. - It doesn't register the DesktopBackground COM server - It doesn't create a start menu shortcut with the AUMID - It doesn't check for .Net Framework 4.8 or later - It doesn't try to install .Net Framework 4.8 or later if not there - It doesn't have any customised backgrounds... - It doesn't ask to run DisplayMagician when install is finished
95 lines
4.0 KiB
C#
95 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using McMaster.Extensions.CommandLineUtils;
|
|
using McMaster.Extensions.CommandLineUtils.Validation;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using DisplayMagicianShared;
|
|
using DisplayMagician.GameLibraries;
|
|
using System.Text.RegularExpressions;
|
|
using System.ServiceModel.Dispatcher;
|
|
|
|
namespace DisplayMagician
|
|
{
|
|
class ProfileMustExistValidator : IArgumentValidator
|
|
{
|
|
public ValidationResult GetValidationResult(CommandArgument argumentProfileName, ValidationContext context)
|
|
{
|
|
// This validator only runs if there is a value
|
|
if (argumentProfileName.Value == "") return ValidationResult.Success;
|
|
var profileName = (string)argumentProfileName.Value;
|
|
|
|
// Try to find the Profile Name
|
|
if (!ProfileRepository.ContainsProfile(profileName))
|
|
{
|
|
return new ValidationResult($"Couldn't find Profile Name or ID supplied via command line: '{profileName}'. Please check the Profile Name or ID you supplied on the command line is correct.");
|
|
}
|
|
|
|
ProfileItem profile = ProfileRepository.GetProfile(profileName);
|
|
Console.WriteLine($"Using Profile: '{profile.Name}' (ID:{profile.UUID})");
|
|
return ValidationResult.Success;
|
|
}
|
|
}
|
|
|
|
class ShortcutMustExistValidator : IArgumentValidator
|
|
{
|
|
public ValidationResult GetValidationResult(CommandArgument argumentShortcutName, ValidationContext context)
|
|
{
|
|
// This validator only runs if there is a string provided
|
|
if (argumentShortcutName.Value == "") return ValidationResult.Success;
|
|
string shortcutName = (string) argumentShortcutName.Value;
|
|
|
|
// Check if the UUID or ShortcutName are provided
|
|
if (!ShortcutRepository.ContainsShortcut(shortcutName))
|
|
{
|
|
return new ValidationResult($"Couldn't find Shortcut Name supplied via command line: '{shortcutName}'. Please check the Shortcut Name you supplied on the command line is correct.");
|
|
}
|
|
|
|
ShortcutItem shortcut = ShortcutRepository.GetShortcut(shortcutName);
|
|
Console.WriteLine($"Using Shortcut: '{shortcut.Name}' (ID: {shortcut.UUID})");
|
|
return ValidationResult.Success;
|
|
}
|
|
}
|
|
|
|
|
|
class FileOptionMustExistValidator : IOptionValidator
|
|
{
|
|
public ValidationResult GetValidationResult(CommandOption optionFullFileName, ValidationContext context)
|
|
{
|
|
// This validator only runs if there is a string provided
|
|
if (optionFullFileName.Value() == "") return ValidationResult.Success;
|
|
var fileNameAndPath = optionFullFileName.Value();
|
|
|
|
// Check that the file exists
|
|
if (!File.Exists(fileNameAndPath))
|
|
{
|
|
return new ValidationResult($"Couldn't find the file '{optionFullFileName.Value()}' supplied to '{optionFullFileName.LongName}'. Please check you specified the full path to the file on the command line.");
|
|
}
|
|
|
|
return ValidationResult.Success;
|
|
}
|
|
}
|
|
|
|
class FileArgumentMustExistValidator : IArgumentValidator
|
|
{
|
|
public ValidationResult GetValidationResult(CommandArgument argumentFullFileName, ValidationContext context)
|
|
{
|
|
// This validator only runs if there is a string provided
|
|
if (argumentFullFileName.Value == "") return ValidationResult.Success;
|
|
var fileNameAndPath = argumentFullFileName.Value;
|
|
|
|
// Check that the file exists
|
|
if (!File.Exists(fileNameAndPath))
|
|
{
|
|
return new ValidationResult($"Couldn't find the file '{argumentFullFileName.Value}' supplied to '{argumentFullFileName.Name}'. Please check you specified the full path to the file on the command line.");
|
|
}
|
|
|
|
return ValidationResult.Success;
|
|
}
|
|
}
|
|
|
|
}
|