<commit_before>﻿using Revolution;
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Media.Animation;

namespace WpfTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public enum Pass
        {
            PassOne,
            PassTwo
        }

        private string StardewFile { get; set; }
        private BackgroundWorker Packer { get; set; }

        public MainWindow()
        {
            //Add Constants
            Resources.Add("ProgramName", Constants.ProgramName);

            InitializeComponent();
            canvasLoading.IsHitTestVisible = false;
            canvasComplete.IsHitTestVisible = false;
        }

        private void buttonFindFile_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog 
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            
            // Set filter for file extension and default file extension 
            dlg.DefaultExt = ".exe";
            dlg.Filter = "Executable Files|*.exe";

            // Display OpenFileDialog by calling ShowDialog method 
            Nullable<bool> result = dlg.ShowDialog();
            
            // Get the selected file name and display in a TextBox 
            if (result == true)
            {
                // Open document 
                string filename = dlg.FileName;
                textBoxExecPath.Text = filename;
                StardewFile = filename;
            }
        }

        private void buttonInstall_Click(object sender, RoutedEventArgs e)
        {
            SwitchToInstallationUI();
            Packer = new BackgroundWorker();
            Packer.DoWork += Packer_DoWork;
            Packer.ProgressChanged += Packer_ProgressChanged;
            Packer.RunWorkerCompleted += Packer_RunWorkerCompleted;
            Packer.WorkerReportsProgress = true;
            Packer.RunWorkerAsync();
        }

        private void Packer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            canvasComplete.Opacity = 1.0f;
            canvasLoading.Opacity = 0.0f;
            canvasComplete.IsHitTestVisible = true;
            canvasLoading.IsHitTestVisible = false;
        }

        private void Packer_DoWork(object sender, DoWorkEventArgs e)
        {
            var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));

            try
            {
                var revolutionExe = Path.GetDirectoryName(StardewFile) + "\\Stardew Revolution.exe";

                Packer.ReportProgress(10, "Creating Temp Directory");
                var outputDirectory = Path.GetDirectoryName(StardewFile);
                Directory.CreateDirectory(tempDirectory);
                Directory.SetCurrentDirectory(tempDirectory);
                File.Copy(StardewFile, tempDirectory + "\\Stardew Valley.exe");
                
                Packer.ReportProgress(20, "Unpackaging Contents");
                ExtractDll(tempDirectory);
                
                Packer.ReportProgress(40, "Injecting Stardew Valley - Pass 1");
                DoInstallationPass1(StardewFile);
                
                Packer.ReportProgress(60, "Injecting Stardew Valley - Pass 2");
                DoInstallationPass2(revolutionExe);
            }<commit_msg>Installer now copies SMAPI compatibility dll<commit_after>﻿using Revolution;
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Media.Animation;

namespace WpfTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public enum Pass
        {
            PassOne,
            PassTwo
        }

        private string StardewFile { get; set; }
        private BackgroundWorker Packer { get; set; }

        public MainWindow()
        {
            //Add Constants
            Resources.Add("ProgramName", Constants.ProgramName);

            InitializeComponent();
            canvasLoading.IsHitTestVisible = false;
            canvasComplete.IsHitTestVisible = false;
        }

        private void buttonFindFile_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog 
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            
            // Set filter for file extension and default file extension 
            dlg.DefaultExt = ".exe";
            dlg.Filter = "Executable Files|*.exe";

            // Display OpenFileDialog by calling ShowDialog method 
            Nullable<bool> result = dlg.ShowDialog();
            
            // Get the selected file name and display in a TextBox 
            if (result == true)
            {
                // Open document 
                string filename = dlg.FileName;
                textBoxExecPath.Text = filename;
                StardewFile = filename;
            }
        }

        private void buttonInstall_Click(object sender, RoutedEventArgs e)
        {
            SwitchToInstallationUI();
            Packer = new BackgroundWorker();
            Packer.DoWork += Packer_DoWork;
            Packer.ProgressChanged += Packer_ProgressChanged;
            Packer.RunWorkerCompleted += Packer_RunWorkerCompleted;
            Packer.WorkerReportsProgress = true;
            Packer.RunWorkerAsync();
        }

        private void Packer_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            canvasComplete.Opacity = 1.0f;
            canvasLoading.Opacity = 0.0f;
            canvasComplete.IsHitTestVisible = true;
            canvasLoading.IsHitTestVisible = false;
        }

        private void Packer_DoWork(object sender, DoWorkEventArgs e)
        {
            var tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()));
            var outputDirectory = Path.GetDirectoryName(StardewFile);

            try
            {
                var revolutionExe = outputDirectory + "\\Stardew Revolution.exe";

                Packer.ReportProgress(10, "Creating Temp Directory");
                Directory.CreateDirectory(tempDirectory);
                Directory.SetCurrentDirectory(tempDirectory);
                File.Copy(StardewFile, tempDirectory + "\\Stardew Valley.exe");
                
                Packer.ReportProgress(20, "Unpackaging Contents");
                ExtractDll(tempDirectory);
                
                Packer.ReportProgress(40, "Injecting Stardew Valley - Pass 1");
                DoInstallationPass1(StardewFile);
                
                Packer.ReportProgress(60, "Injecting Stardew Valley - Pass 2");
                DoInstallationPass2(revolutionExe);

                Packer.ReportProgress(60, "Copying SMAPI Compatibility Layer");
                File.Copy("StardewModdingAPI.dll", outputDirectory + "\\StardewModdingAPI.dll");
            }
{'fraction_non_alphanumeric': 0.07838807617996135, 'fraction_numerical': 0.005796301407673199, 'mean_word_length': 1.8610343466245558, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '8051', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1728, 'n_words': 397}