예제 #1
0
        private void ClickedOK(object sender, EventArgs e)
        {
            if (rbDXGI.Checked)
            {
                Api = ApiDialogResult.DXGI;
            }
            else if (rbD3D11.Checked)
            {
                Api = ApiDialogResult.D3D11;
            }
            else if (rbD3D9.Checked)
            {
                Api = ApiDialogResult.D3D9;
            }
            else if (rbOpenGL32.Checked)
            {
                Api = ApiDialogResult.OpenGL32;
            }
            else if (rbDInput8.Checked)
            {
                Api = ApiDialogResult.DInput8;
            }

            DialogResult = DialogResult.OK;
            Close();
        }
예제 #2
0
        private void FinalizeLocalInstall()
        {
            if (CancelOperation)
            {
                ActiveOperation = CancelOperation = false;
                return;
            }

            try
            {
                string DLLFileName    = (LocalInstall64bit) ? "SpecialK64.dll" : "SpecialK32.dll";
                string TargetFileName = LocalInstallAPI.ToString().ToLower() + ".dll";

                Directory.CreateDirectory(_tmpExtractionPath);
                Log("Extracting temporary files to " + _tmpExtractionPath);
                ExtractFile(_tmpDownloadPath, _tmpExtractionPath, DLLFileName);

                if (File.Exists(_tmpExtractionPath + "\\" + DLLFileName))
                {
                    if (File.Exists(TargetInstallPath + "\\" + TargetFileName))
                    {
                        Log(TargetInstallPath + "\\" + TargetFileName + " already exists. Prompting user on how to proceed.");

                        switch (MessageBox.Show(TargetInstallPath + "\\" + TargetFileName + " already exists.\r\n\r\nAre you sure you want to overwrite it?", "File already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                        case DialogResult.Yes:
                            Log("User decided to overwrite the existing file.");
                            File.Copy(_tmpExtractionPath + "\\" + DLLFileName, TargetInstallPath + "\\" + TargetFileName, true);
                            Log("Copied " + DLLFileName + " to " + TargetInstallPath + "\\" + TargetFileName);
                            break;

                        case DialogResult.No:
                            CancelOperation = true;
                            Log("User decided to abort the installation!");
                            break;
                        }
                        // Fixes issue with window appearing behind another application.
                        BringToFront();
                    }
                    else
                    {
                        File.Copy(_tmpExtractionPath + "\\" + DLLFileName, TargetInstallPath + "\\" + TargetFileName);
                        Log("Copied " + _tmpExtractionPath + "\\" + DLLFileName + " to " + TargetInstallPath + "\\" + TargetFileName);
                    }

                    // Remove existing install if 'Clean Install' is checked
                    if (cbCleanInstall.Checked && File.Exists(TargetInstallPath + "\\" + LocalInstallAPI.ToString().ToLower() + ".ini") && !CancelOperation)
                    {
                        Log("Removing existing config file...");
                        File.Delete(TargetInstallPath + "\\" + LocalInstallAPI.ToString().ToLower() + ".ini");
                    }
                }
                else
                {
                    Log("Failed to locate appropriate DLL file in the extracted files!");
                }
            }
            catch
            {
            }

            Log("Cleaning up temporary files...");
            Directory.Delete(_tmpExtractionPath, true);

            LocalInstallAPI   = ApiDialogResult.None;
            LocalInstall64bit = false;
            TargetInstallPath = "";
            ActiveOperation   = CancelOperation = false;

            Log("\r\nInstallation finished!\r\n");
        }
예제 #3
0
        private void PerformLocalInstall()
        {
            ActiveOperation = true;

            /*
             * 1. Browse for appropriate executable.
             * 2. Download and extract Special K archive to a dummy folder.
             * 3. Detect 32-bit or 64-bit from the file executable.
             * 4. Prompt user about API support (might be able to be automated in the future?)
             * 5. Move appropriate SpecialK32/64.dll files to the target folder.
             *
             */

            ApiDialog      apiDialog  = new ApiDialog();
            OpenFileDialog fileDialog = new OpenFileDialog
            {
                Filter           = "Game executables (*.exe)|*.exe",
                Title            = "Browse for game executable",
                CheckFileExists  = true,
                CheckPathExists  = true,
                Multiselect      = false,
                ValidateNames    = true,
                RestoreDirectory = true
            };

            if (fileDialog.ShowDialog() == DialogResult.OK && apiDialog.ShowDialog() == DialogResult.OK)
            {
                LocalInstallAPI = apiDialog.Api;
                Log("Attempting to install local (game-specific) wrapper DLLs for " + fileDialog.FileName);

                FilePEType type = GetFilePE(fileDialog.FileName);

                if (type == FilePEType.IMAGE_FILE_MACHINE_AMD64)
                {
                    LocalInstall64bit = true; // 64-bit
                }
                else if (type == FilePEType.IMAGE_FILE_MACHINE_I386)
                {
                    LocalInstall64bit = false; // 32-bit, or AnyCPU for .NET-based games
                }
                else
                {
                    Log("Unknown executable architecture."); // Unknown
                }
                TargetInstallPath = Path.GetDirectoryName(fileDialog.FileName);

                bool fileExists = File.Exists(_tmpDownloadPath);
                bool cancel     = false;

                if (fileExists)
                {
                    Log("A file called " + _tmpArchiveName + " was found in the downloads folder. Prompting user on how to proceed.");
                    switch (MessageBox.Show("A file called " + _tmpArchiveName + " was found in the downloads folder.\r\nDo you want to use that one?\r\n\r\nClicking 'No' will redownload the file from the Internet.", "Found local file for selected version", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button3))
                    {
                    case DialogResult.Yes:
                        Log("User chose to reuse the local copy found.");
                        break;

                    case DialogResult.No:
                        fileExists = false;
                        Log("User chose to redownload the archive from the Internet.");
                        break;

                    case DialogResult.Cancel:
                        cancel          = true;
                        ActiveOperation = false;
                        Log("User canceled the install process.");
                        break;
                    }
                }

                if (cancel == false)
                {
                    if (fileExists == false)
                    {
                        Log("Downloading " + _tmpDownloadURL);
                        using (OngoingDownload = new WebClient())
                        {
                            OngoingDownload.DownloadProgressChanged += OnDownloadProgressChanged;
                            OngoingDownload.DownloadFileCompleted   += (object sender, AsyncCompletedEventArgs e) =>
                            {
                                if (!tsProgress.IsDisposed)
                                {
                                    tsProgress.Visible = false;
                                }

                                if (e.Cancelled || e.Error != null)
                                {
                                    if (e.Cancelled)
                                    {
                                        Log("Download cancelled!");
                                    }
                                    else if (e.Error != null)
                                    {
                                        Log("Download failed!");
                                        Log("Error message: " + e.Error.Message + "\r\n");
                                    }

                                    Log("Cleaning up incomplete file " + _tmpDownloadPath);
                                    if (File.Exists(_tmpDownloadPath))
                                    {
                                        File.Delete(_tmpDownloadPath);
                                    }

                                    ActiveOperation = false;
                                    CancelOperation = true;
                                    OngoingDownload.Dispose();
                                    OngoingDownload = null;
                                    return;
                                }

                                Log("Download completed!");
                                FinalizeLocalInstall();
                                OngoingDownload.Dispose();
                                OngoingDownload = null;
                            };
                            OngoingDownload.DownloadFileAsync(new Uri(_tmpDownloadURL), _tmpDownloadPath);
                        }
                    }
                    else
                    {
                        FinalizeLocalInstall();
                    }
                }
            }
            else
            {
                ActiveOperation = CancelOperation = false;
            }
        }
예제 #4
0
 private void ClickedCancel(object sender, EventArgs e)
 {
     Api          = ApiDialogResult.None;
     DialogResult = DialogResult.Cancel;
     Close();
 }