/// <summary/>
    /// <param name="parameter">Optional parameter. See <see cref="AddApplicationCommandParams"/>.</param>
    public async Task ExecuteAsync(object?parameter)
    {
        var commandParam = parameter as AddApplicationCommandParams;
        var param        = commandParam ?? new AddApplicationCommandParams();

        // Select EXE
        string exePath = SelectEXEFile();

        if (string.IsNullOrEmpty(exePath) || !File.Exists(exePath))
        {
            param.ResultCreatedApplication = false;
            return;
        }

        // Get file information and populate initial application details.
        exePath = SymlinkResolver.GetFinalPathName(exePath);
        var fileInfo = FileVersionInfo.GetVersionInfo(exePath);
        var config   = new ApplicationConfig(Path.GetFileName(fileInfo.FileName).ToLower(), fileInfo.ProductName, exePath);

        // Set AppName if empty & Ensure no duplicate ID.
        if (string.IsNullOrEmpty(config.AppName))
        {
            config.AppName = config.AppId;
        }

        UpdateIdIfDuplicate(config);

        // Get paths.
        var    loaderConfig = IoC.Get <LoaderConfig>();
        string applicationConfigDirectory = loaderConfig.GetApplicationConfigDirectory();
        string applicationDirectory       = Path.Combine(applicationConfigDirectory, config.AppId);
        string applicationConfigFile      = Path.Combine(applicationDirectory, ApplicationConfig.ConfigFileName);

        // Work with the index.
        try
        {
            var command = new QueryCommunityIndexCommand(new PathTuple <ApplicationConfig>(applicationConfigFile, config));
            await command.ExecuteAsync();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }

        // Write file to disk.
        Directory.CreateDirectory(applicationDirectory);
        IConfig <ApplicationConfig> .ToPath(config, applicationConfigFile);

        // Listen to event for when the new application is discovered.
        _newConfig = config;
        _configService.Items.CollectionChanged += ApplicationsChanged;

        // Set return value
        param.ResultCreatedApplication = true;
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Used to set the new executable path for the application.
    /// </summary>
    public void SetNewExecutablePath()
    {
        var result = SelectEXEFile();

        if (string.IsNullOrEmpty(result))
        {
            return;
        }

        result = SymlinkResolver.GetFinalPathName(result);
        if (!Path.GetFileName(Application.Config.AppLocation).Equals(Path.GetFileName(result), StringComparison.OrdinalIgnoreCase))
        {
            Actions.DisplayMessagebox(Resources.AddAppWarningTitle.Get(), Resources.AddAppWarning.Get());
        }

        Application.Config.AppLocation = result;
    }