Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';无法正确读取设置_C#_Wpf_Backup_Settings - Fatal编程技术网

C# Can';无法正确读取设置

C# Can';无法正确读取设置,c#,wpf,backup,settings,C#,Wpf,Backup,Settings,我最近将我的游戏的启动器重新制作成WPF。虽然大多数代码都运行良好,但当我将其移到另一个地方时,我正在开发的一个特定功能完全崩溃了 我正在开发的功能是一个简单的备份系统。设置很简单:用户转到“保存管理器”并勾选“自动备份”设置。这是勾号的XAML代码: <CheckBox x:Name="AutoBackupCheckbox" Content="{x:Static properties1:Resources.EnableBackupsString}" HorizontalAlignm

我最近将我的游戏的启动器重新制作成WPF。虽然大多数代码都运行良好,但当我将其移到另一个地方时,我正在开发的一个特定功能完全崩溃了

我正在开发的功能是一个简单的备份系统。设置很简单:用户转到“保存管理器”并勾选“自动备份”设置。这是勾号的XAML代码:

  <CheckBox x:Name="AutoBackupCheckbox" Content="{x:Static  properties1:Resources.EnableBackupsString}" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top" Checked="AutoBackupCheckbox_CheckChanged" Unchecked="AutoBackupCheckbox_CheckChanged" IsChecked="{Binding Source={x:Static properties1:Settings.Default},Path=AutoBackupEnabled}"/>
问题是代码被牢牢地固定在True上。我不知道是什么迫使我这么做。这会使备份系统始终处于禁用状态,因为在调试期间,我总是看到设置为true时返回false

以下是启动器在启动时执行的操作代码:

        {
        var jumperDeck = new JumpList();
        jumperDeck.JumpItems.Add(JumperCatalog.StartGameJumpTask);
        jumperDeck.JumpItems.Add(JumperCatalog.QuickLoadJumpTask);
        jumperDeck.JumpItems.Add(JumperCatalog.SaveManagerTask);
        jumperDeck.JumpItems.Add(JumperCatalog.ResetLauncherLockTask);
        jumperDeck.JumpItems.Add(JumperCatalog.BugReporterJumpTask);
        jumperDeck.JumpItems.Add(JumperCatalog.EManualJumpTask);
        jumperDeck.JumpItems.Add(JumperCatalog.DiscordJumpTask);
        jumperDeck.JumpItems.Add(JumperCatalog.ReadmeJumpTask);
        JumpList.SetJumpList(Application.Current, jumperDeck);

        var assembly = Assembly.GetExecutingAssembly();
        {
            var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
            var version = fvi.FileVersion;
            LauncherVersionLabel.Content = LauncherVersionLabel.Content + @" (" + version + @")";
        }
        GameVersionLabel.Content = GameVersionLabel.Content + @" (0.20.4-20180117)";
        var args = Environment.GetCommandLineArgs();
        //if (IsCompatible == false)
        //{
        //    Form osIncompatible = new IncompatibleVersion();
        //    osIncompatible.ShowDialog();
        //    Close();
        //}
        foreach (var arg in args)
            switch (arg)
            {
                case "-ResetLauncherLock":
                    Settings.Default.SkipLauncher = false;
                    Settings.Default.Save();
                    break;
                case "-NoLauncher":
                case "-QuickLoad":
                    if (!File.Exists(PlayerFile) || !File.Exists(RgssLib) || !File.Exists(InputPath))
                    {
                        MessageBox.Show(Properties.Resources.FileMissingLabelString, Properties.Resources.CriticalFailiureString, MessageBoxButton.OK,
                            MessageBoxImage.Error);
                    }
                    else if (arg == "-QuickLoad")
                    {
                        QuickLoad();
                    }
                    else
                    {
                        NormalStart();
                    }
                    break;
            }
        if (Settings.Default.SkipLauncher)
            if (!File.Exists(PlayerFile) || !File.Exists(RgssLib) || !File.Exists(InputPath))
            {
                MessageBox.Show(Properties.Resources.FileMissingLabelString, Properties.Resources.CriticalFailiureString, MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }
            else
            {
                NormalStart();
            }
        IoController.DiskCheck(CommonVariables.FolderCheck);
        if (!CommonVariables.IsDriveReady)
        {
            MessageBox.Show(Properties.Resources.DNRString, Properties.Resources.DNRTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
            Close();
        }
        if (CommonVariables.PermissionError || CommonVariables.SpaceError)
        {
            CanSaveLabel.Content = Properties.Resources.CommonWordNo;
            CanSaveLabel.Foreground = Brushes.DarkRed;

            if (CommonVariables.PermissionError)
            {
                CanSaveLabel.Content = CanSaveLabel.Content + Properties.Resources.DiagnositcPermissionError;
                EngineErrorLabel.Content = Properties.Resources.BackupPermissionError;
            }
            else
            {
                CanSaveLabel.Content = CanSaveLabel.Content + Properties.Resources.DiagnosticSpaceError;
                EngineErrorLabel.Content = Properties.Resources.NotEnoughSpaceLabelString;
            }
            EngineErrorLabel.Visibility = CommonVariables.PermissionError ? Visibility.Visible : Visibility.Hidden;
        }
        else
        {
            CanSaveLabel.Content = Properties.Resources.CommonWordYes;
            CanSaveLabel.Foreground = Brushes.ForestGreen;
        }

        var gfMiss = 0;

        if (File.Exists(PlayerFile))
        {
            var gamever = FileVersionInfo.GetVersionInfo(PlayerFile);
            Rgss3PlayLabel.Content = Properties.Resources.PresentString + " " + @"(" + gamever.FileVersion + @")";
            Rgss3PlayLabel.Foreground = Brushes.ForestGreen;
        }
        else
        {
            Rgss3PlayLabel.Content = Properties.Resources.MissingString;
            Rgss3PlayLabel.Foreground = Brushes.DarkRed;
            gfMiss = gfMiss + 1;
        }

        if (File.Exists(RgssLib))
        {
            var libver = FileVersionInfo.GetVersionInfo(RgssLib);
            Rgss3LibLabel.Content = Properties.Resources.PresentString + " " + @"(" + libver.FileVersion + @")";
            Rgss3LibLabel.Foreground = Brushes.ForestGreen;
        }
        else
        {
            Rgss3LibLabel.Content = Properties.Resources.MissingString;
            Rgss3LibLabel.Foreground = Brushes.DarkRed;
            gfMiss = gfMiss + 1;
        }
        if (File.Exists(GameFile))
        {
            FileAvailiable.Content = Properties.Resources.PresentString;
            FileAvailiable.Foreground = Brushes.ForestGreen;
        }
        else
        {
            FileAvailiable.Content = Properties.Resources.MissingString;
            FileAvailiable.Foreground = Brushes.DarkRed;
            gfMiss = gfMiss + 1;
        }
        if (File.Exists(InputPath))
        {
            var inputver = FileVersionInfo.GetVersionInfo(InputPath);
            InputLabel.Content = Properties.Resources.PresentString + @"(" + inputver.FileVersion + @")";
            InputLabel.Foreground = Brushes.ForestGreen;
        }
        else
        {
            InputLabel.Content = Properties.Resources.MissingString;
            InputLabel.Foreground = Brushes.DarkRed;
            gfMiss = gfMiss + 1;
        }

        if (File.Exists(RgssExtFile))
        {
            var rex = FileVersionInfo.GetVersionInfo(RgssExtFile);
            RexVersionLabel.Foreground = Brushes.ForestGreen;
            RexVersionLabel.Content = Properties.Resources.PresentString +" (" + rex.FileVersion + ")";
        }
        else
        {
            RexVersionLabel.Foreground = Brushes.DarkRed;
            RexVersionLabel.Content = Properties.Resources.MissingString;
            gfMiss = gfMiss + 1;
        }

        if (File.Exists(CoreLibLocation))
        {
            var clx = FileVersionInfo.GetVersionInfo(CoreLibLocation);
            CoreLibraryLabel.Content = Properties.Resources.PresentString + " (" + clx.FileVersion + ")";
            CoreLibraryLabel.Foreground = Brushes.ForestGreen;
        }
        else
        {
            CoreLibraryLabel.Content = Properties.Resources.MissingString;
            CoreLibraryLabel.Foreground = Brushes.DarkRed;
            gfMiss += 1;
        }

        if (gfMiss > 0)
        {
            GfPresentLabel.Content = Properties.Resources.CommonWordNo;
            GfPresentLabel.Foreground = Brushes.DarkRed;
            EngineErrorLabel.Content = Properties.Resources.FileMissingLabelString;
            EngineErrorLabel.Visibility = Visibility.Visible;
            PlayButton.IsEnabled = false;
            SkipSplashCheckbox.IsEnabled = false;
            DisableLauncherCheckbox.IsEnabled = false;
        }
        else
        {
            GfPresentLabel.Content = Properties.Resources.CommonWordYes;
            GfPresentLabel.Foreground = Brushes.ForestGreen;
            if (!Directory.Exists(CommonVariables.SaveLocation))
            {
                Directory.CreateDirectory(CommonVariables.SaveLocation);
                CommonVariables.IsSaveAvailable = false;
            }
            else
            {
                CommonVariables.IsSaveAvailable = NorthbridgeCommonTasks.GetFolderSaves();
            }
        }
        ExportButton.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable;
        QuickLoadCommand.IsEnabled = CommonVariables.IsSaveAvailable;
        AutoBackupCheckbox.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable;
        LocationBackup.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable && (bool)AutoBackupCheckbox.IsChecked;
        //ArchiveBckup.Enabled = gfMiss == 0 && CommonVariables.IsSaveAvailable && (bool)AutoBackupCheckbox.IsChecked;
        DeleteButton.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable;
        TestBackupButton.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable &&
                                     AutoBackupCheckbox.IsChecked == true &&
                                     LocationBackup.Text != null;
        BuildZipCheckbox.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable;
        BrowseButton.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable && AutoBackupCheckbox.IsEnabled;
        RestoreBackupButton.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable &&
                                        AutoBackupCheckbox.IsChecked == true;
        DeleteBackupButton.IsEnabled = gfMiss == 0 && CommonVariables.IsSaveAvailable;
        ImportButton.IsEnabled = gfMiss == 0 && !CommonVariables.PermissionError && !CommonVariables.SpaceError;
        GpuControl.IsEnabled = gfMiss == 0;
        //SlotSelectCheckBox.Enabled = ImportButton.IsEnabled;
        ReadmeButton.IsEnabled = File.Exists(Ci == "el-GR" ? GreekReadme : ReadmeFile);
        AutoBackupCheckbox.IsChecked = Settings.Default.AutoBackupEnabled;
        SkipSplashCheckbox.IsChecked = Settings.Default.AcceleratedMode;
        if (!File.Exists(Directory.GetParent(Assembly.GetExecutingAssembly().Location) + "\\RMVXA-GL.dll")) GpuControl.Visibility = Visibility.Hidden;
        GpuControl.IsChecked = Settings.Default.EnableGPUAccelration;
        SingleBackupModeCheckbox.IsEnabled = gfMiss == 0 && (bool)AutoBackupCheckbox.IsChecked;
    }
下面是它启动游戏的代码:

        private void NormalStart()
    {
        Thread.Sleep(500);
        Hide();
        CommonProcedures.CheckDrive();
        GameInfo.Arguments = Settings.Default.AcceleratedMode ? "-playnow -astart" : "-playnow";
        if (!Settings.Default.EnableGPUAccelration) GameInfo.Arguments = GameInfo.Arguments + " -NoGPU";
        if (Settings.Default.CompatMode)
        {
            GameInfo.Arguments = GameInfo.Arguments + " -compatmode";
            Directory.CreateDirectory("C:\\Immortal Sins\\Config\\");
            IoController.DirectoryCopy(ConfigArea, "c:\\Immortal Sins\\Config\\", true);
        }
        _gameProcess.StartInfo = GameInfo;
        if (Settings.Default.AutoBackupEnabled && Settings.Default.AutoBackupLocation != null)
            BackupEngine.MonitorSetupCode();
        _gameProcess.Start();
        _gameProcess.WaitForExit();
        if (Settings.Default.AutoBackupEnabled && Settings.Default.AutoBackupLocation != null &&
            BackupEngine.CountChanges > 0 &&
            !Settings.Default.SingleBackupMode) BackupEngine.SnapshotBackupCode();
        else if (Settings.Default.AutoBackupEnabled && Settings.Default.AutoBackupLocation != null &&
                 BackupEngine.CountChanges > 0 && Settings.Default.SingleBackupMode && Settings.Default.ArchiveBackups)
            BackupEngine.SingleBackupArchive();
        if (Settings.Default.CompatMode)
        {
            IoController.DirectoryCopy("C:\\Immortal Sins\\Config\\", ConfigArea, true);
            Directory.Delete("C:\\Immortal Sins\\", true);
        }
        Close();
    }

使用
IsChecked
,而不是
isnable
IsEnabled
始终为真,因为它仅检查复选框是否已启用。如果用户选中复选框,则必须使用IsChecked属性。
文档:

我发现了问题。还有一个组件一直在发送true(和false),因为该组件上的数据绑定是双向的,而不是单向的。这和迈克的解决方案一起解决了这个问题

        private void NormalStart()
    {
        Thread.Sleep(500);
        Hide();
        CommonProcedures.CheckDrive();
        GameInfo.Arguments = Settings.Default.AcceleratedMode ? "-playnow -astart" : "-playnow";
        if (!Settings.Default.EnableGPUAccelration) GameInfo.Arguments = GameInfo.Arguments + " -NoGPU";
        if (Settings.Default.CompatMode)
        {
            GameInfo.Arguments = GameInfo.Arguments + " -compatmode";
            Directory.CreateDirectory("C:\\Immortal Sins\\Config\\");
            IoController.DirectoryCopy(ConfigArea, "c:\\Immortal Sins\\Config\\", true);
        }
        _gameProcess.StartInfo = GameInfo;
        if (Settings.Default.AutoBackupEnabled && Settings.Default.AutoBackupLocation != null)
            BackupEngine.MonitorSetupCode();
        _gameProcess.Start();
        _gameProcess.WaitForExit();
        if (Settings.Default.AutoBackupEnabled && Settings.Default.AutoBackupLocation != null &&
            BackupEngine.CountChanges > 0 &&
            !Settings.Default.SingleBackupMode) BackupEngine.SnapshotBackupCode();
        else if (Settings.Default.AutoBackupEnabled && Settings.Default.AutoBackupLocation != null &&
                 BackupEngine.CountChanges > 0 && Settings.Default.SingleBackupMode && Settings.Default.ArchiveBackups)
            BackupEngine.SingleBackupArchive();
        if (Settings.Default.CompatMode)
        {
            IoController.DirectoryCopy("C:\\Immortal Sins\\Config\\", ConfigArea, true);
            Directory.Delete("C:\\Immortal Sins\\", true);
        }
        Close();
    }