<commit_before>﻿using Playnite.Models;
using Playnite.SDK.Models;
using Playnite.Settings;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Playnite
{
    public static class GameExtensions
    {
        public static Game GetGameFromExecutable(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"Cannot create game from executable, {path} not found.");
            }

            var game = new Game();

            if (string.Equals(Path.GetExtension(path), ".lnk", StringComparison.InvariantCultureIgnoreCase))
            {
                var prog = Common.System.Programs.ParseShortcut(path);
                var file = new FileInfo(prog.Path);
                var versionInfo = FileVersionInfo.GetVersionInfo(prog.Path);
                var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(file.DirectoryName).Name;
                game.Name = programName;
                game.InstallDirectory = prog.WorkDir;
                game.PlayAction = new GameAction()
                {
                    Type = GameActionType.File,
                    WorkingDir = "{InstallDir}",
                    Path = prog.Path.Replace(game.InstallDirectory, "").Trim(Path.DirectorySeparatorChar),
                    Arguments = prog.Arguments
                };
            }
            else
            {
                var file = new FileInfo(path);
                var versionInfo = FileVersionInfo.GetVersionInfo(path);
                var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(file.DirectoryName).Name;
                game.Name = programName;
                game.InstallDirectory = file.DirectoryName;
                game.PlayAction = new GameAction()
                {
                    Type = GameActionType.File,
                    WorkingDir = "{InstallDir}",
                    Path = file.Name
                };
            };

            game.State.Installed = true;
            return game;
        }

        public static string ExpandVariables(this Game game, string inputString)
        {
            if (string.IsNullOrEmpty(inputString))
            {
                return inputString;<commit_msg>Drag and drop import fix.<commit_after>﻿using Playnite.Models;
using Playnite.SDK.Models;
using Playnite.Settings;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Playnite
{
    public static class GameExtensions
    {
        public static Game GetGameFromExecutable(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException($"Cannot create game from executable, {path} not found.");
            }

            var game = new Game();

            if (string.Equals(Path.GetExtension(path), ".lnk", StringComparison.InvariantCultureIgnoreCase))
            {
                var prog = Common.System.Programs.ParseShortcut(path);
                var file = new FileInfo(prog.Path);
                var versionInfo = FileVersionInfo.GetVersionInfo(prog.Path);
                var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(file.DirectoryName).Name;
                game.Name = programName;
                game.InstallDirectory = prog.WorkDir;
                game.PlayAction = new GameAction()
                {
                    Type = GameActionType.File,
                    WorkingDir = "{InstallDir}",
                    Path = prog.Path.Substring(game.InstallDirectory.Length).Trim(Path.DirectorySeparatorChar),
                    Arguments = prog.Arguments
                };
            }
            else
            {
                var file = new FileInfo(path);
                var versionInfo = FileVersionInfo.GetVersionInfo(path);
                var programName = !string.IsNullOrEmpty(versionInfo.ProductName?.Trim()) ? versionInfo.ProductName : new DirectoryInfo(file.DirectoryName).Name;
                game.Name = programName;
                game.InstallDirectory = file.DirectoryName;
                game.PlayAction = new GameAction()
                {
                    Type = GameActionType.File,
                    WorkingDir = "{InstallDir}",
                    Path = file.Name
                };
            };

            game.State.Installed = true;
            return game;
        }

        public static string ExpandVariables(this Game game, string inputString)
        {
            if (string.IsNullOrEmpty(inputString))
            {
                return inputString;
{'fraction_non_alphanumeric': 0.0873353596757852, 'fraction_numerical': 0.0, 'mean_word_length': 1.7668161434977578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1681016', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1156, 'n_words': 254}