Ejemplo n.º 1
0
        public bool CreateFile(string resourceName, string destinationFileName, Version oldVersion = null, Version newVersion = null)
        {
            if (destinationFileName == null)
            {
                destinationFileName = resourceName;
            }
            DialogResult answer;
            var          form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var fileName = new FileInfo(destinationFileName).FullName;

            if (newVersion == null)
            {
                answer = form.ShowForm(
                    string.Format("'{0}' was not found.\r\nThis file is required for emulator to function properly.\r\n\r\nDo you want to create this file?", fileName),
                    string.Format("'{0}' was not found.", destinationFileName),
                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
            }
            else
            {
                answer = form.ShowForm(
                    string.Format("New version of this file is available:\r\n{0}\r\n\r\nOld version: {1}\r\nNew version: {2}\r\n\r\nDo you want to update this file?", fileName, oldVersion, newVersion),
                    string.Format("New version of '{0}' file is available.", destinationFileName),
                    MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            }
            if (answer == DialogResult.Yes)
            {
                return(AppHelper.WriteFile(resourceName, destinationFileName));
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool CreateFile(string resourceName, string destinationFileName, ProcessorArchitecture oldArchitecture, ProcessorArchitecture newArchitecture)
        {
            if (destinationFileName == null)
            {
                destinationFileName = resourceName;
            }
            DialogResult answer;
            var          form = new MessageBoxForm();

            form.StartPosition = FormStartPosition.CenterParent;
            var oldDesc  = EngineHelper.GetProcessorArchitectureDescription(oldArchitecture);
            var newDesc  = EngineHelper.GetProcessorArchitectureDescription(newArchitecture);
            var fileName = new FileInfo(destinationFileName).Name;

            answer = form.ShowForm(
                string.Format("You are running {2} application but {0} on the disk was built for {1} architecture.\r\n\r\nDo you want to replace {0} file with {2} version?", fileName, oldDesc, newDesc),
                "Processor architecture mismatch.",
                MessageBoxButtons.YesNo, MessageBoxIcon.Information);
            if (answer == DialogResult.Yes)
            {
                return(AppHelper.WriteFile(resourceName, destinationFileName));
            }
            return(true);
        }
Ejemplo n.º 3
0
        // Check game settings against folder.
        public GameRefreshStatus GetDllAndIniStatus(x360ce.Engine.Data.UserGame game, bool fix = false)
        {
            var status = GameRefreshStatus.OK;
            var fi     = new FileInfo(game.FullPath);

            // Check if game file exists.
            if (!fi.Exists)
            {
                return(GameRefreshStatus.ExeNotExist);
            }
            // Check if game is not enabled.
            else if (!game.IsEnabled)
            {
                return(status);
            }
            else
            {
                var content      = GetIniContent(game);
                var bytes        = SettingsHelper.GetFileConentBytes(content, Encoding.Unicode);
                var iniDirectory = Path.GetDirectoryName(game.FullPath);
                var iniFullName  = Path.Combine(iniDirectory, IniFileName);
                var isDifferent  = SettingsHelper.IsDifferent(iniFullName, bytes);
                if (isDifferent)
                {
                    if (fix)
                    {
                        File.WriteAllBytes(iniFullName, bytes);
                    }
                    else
                    {
                        var iniExists = File.Exists(iniFullName);
                        status |= (iniExists ? GameRefreshStatus.IniDifferent : GameRefreshStatus.IniNotExist);
                    }
                }
                var xiValues = ((XInputMask[])Enum.GetValues(typeof(XInputMask))).Where(x => x != XInputMask.None).ToArray();
                // Create dictionary from XInput type and XInput file name.
                var dic = new Dictionary <XInputMask, string>();
                foreach (var value in xiValues)
                {
                    dic.Add(value, Attributes.GetDescription(value));
                }
                // Get names of files: xinput9_1_0.dll, xinput1_1.dll, xinput1_2.dll, xinput1_3.dll, xinput1_4.dll
                var xiFileNames = dic.Values.Distinct();
                // Loop through XInput DLL files.
                foreach (var xiFileName in xiFileNames)
                {
                    // Get enum linked to 64-bit version of the file.
                    var x64Value = dic.First(x => x.Value == xiFileName && x.ToString().Contains("x64")).Key;
                    // Get enum linked to 32-bit version of the file.
                    var x86Value = dic.First(x => x.Value == xiFileName && x.ToString().Contains("x86")).Key;
                    // Get information about XInput DLL file.
                    var xiFullPath = System.IO.Path.Combine(fi.Directory.FullName, xiFileName);
                    var xiFileInfo = new System.IO.FileInfo(xiFullPath);
                    // Determine required architecture.
                    var requiredArchitecture = ProcessorArchitecture.None;
                    var x64Enabled           = ((XInputMask)game.XInputMask).HasFlag(x64Value);
                    var x86Enabled           = ((XInputMask)game.XInputMask).HasFlag(x86Value);
                    if (x86Enabled && x64Enabled)
                    {
                        requiredArchitecture = ProcessorArchitecture.MSIL;
                    }
                    else if (x86Enabled)
                    {
                        requiredArchitecture = ProcessorArchitecture.X86;
                    }
                    else if (x64Enabled)
                    {
                        requiredArchitecture = ProcessorArchitecture.Amd64;
                    }
                    // Get embeded resource name for current xinput file.
                    var resourceName = EngineHelper.GetXInputResoureceName(requiredArchitecture);
                    // If both XInput file CheckBoxes are disabled then...
                    if (requiredArchitecture == ProcessorArchitecture.None)
                    {
                        // If XInput file exists then...
                        if (xiFileInfo.Exists)
                        {
                            if (fix)
                            {
                                // Delete unnecessary XInput file.
                                xiFileInfo.Delete();
                            }
                            else
                            {
                                status |= GameRefreshStatus.XInputFilesUnnecessary;
                            }
                        }
                    }
                    // If XInput file doesn't exists then...
                    else if (!xiFileInfo.Exists)
                    {
                        // Create XInput file.
                        if (fix)
                        {
                            AppHelper.WriteFile(resourceName, xiFileInfo.FullName);
                        }
                        else
                        {
                            status |= GameRefreshStatus.XInputFilesNotExist;
                        }
                    }
                    else
                    {
                        // Get current architecture of XInput DLL.
                        var xiCurrentArchitecture = Engine.Win32.PEReader.GetProcessorArchitecture(xiFullPath);
                        // If processor architectures doesn't match then...
                        if (requiredArchitecture != xiCurrentArchitecture)
                        {
                            // Create XInput file.
                            if (fix)
                            {
                                AppHelper.WriteFile(resourceName, xiFileInfo.FullName);
                            }
                            else
                            {
                                status |= GameRefreshStatus.XInputFilesWrongPlatform;
                            }
                        }
                        else
                        {
                            // Determine if file was created by Microsoft.
                            bool byMicrosoft;
                            // Get version of XInput DLL on the disk.
                            var dllVersion = EngineHelper.GetDllVersion(xiFullPath, out byMicrosoft);
                            // Get version of embeded XInput DLL.
                            var embededVersion = EngineHelper.GetEmbeddedDllVersion(xiCurrentArchitecture);
                            // If file on disk is older then...
                            if (dllVersion < embededVersion)
                            {
                                // Overwrite XInput file.
                                if (fix)
                                {
                                    AppHelper.WriteFile(resourceName, xiFileInfo.FullName);
                                }
                                else
                                {
                                    status |= GameRefreshStatus.XInputFilesOlderVersion;
                                }
                            }
                            else if (dllVersion > embededVersion)
                            {
                                // Allow new version.
                                // return GameRefreshStatus.XInputFileNewerVersion;
                            }
                        }
                    }
                }
            }
            return(status);
        }