Exemplo n.º 1
0
        public void BinaryRoundTripTest()
        {
            UID original = new UID(0xabcd);

            using (MemoryStream stream = new MemoryStream())
            {
                BinaryPropertyListWriter.Write(stream, original);
                stream.Position = 0;
                UID roundtrip = BinaryPropertyListParser.Parse(stream) as UID;
                Assert.Equal(original.Bytes, roundtrip.Bytes);
            }
        }
        public void Roundtrip2Test()
        {
            byte[]   data = File.ReadAllBytes("test-files/plist2.bin");
            NSObject root = PropertyListParser.Parse(data);

            using (MemoryStream actualOutput = new MemoryStream())
                using (Stream expectedOutput = File.OpenRead("test-files/plist2.bin"))
                    using (ValidatingStream validatingStream = new ValidatingStream(actualOutput, expectedOutput))
                    {
                        BinaryPropertyListWriter writer = new BinaryPropertyListWriter(validatingStream);
                        writer.ReuseObjectIds = false;
                        writer.Write(root);
                    }
        }
Exemplo n.º 3
0
        public static void SaveSettings()
        {
            try
            {
                PlatformID ptId = DetectOS.GetRealPlatformID();

                switch (ptId)
                {
                case PlatformID.MacOSX:
                case PlatformID.iOS:
                {
                    var root = new NSDictionary
                    {
                        {
                            "TemporaryFolder", Current.TemporaryFolder
                        },
                        {
                            "DatabasePath", Current.DatabasePath
                        },
                        {
                            "RepositoryPath", Current.RepositoryPath
                        },
                        {
                            "UnArchiverPath", Current.UnArchiverPath
                        },
                        {
                            "CompressionAlgorithm", Current.CompressionAlgorithm.ToString()
                        },
                        {
                            "UseAntivirus", Current.UseAntivirus
                        },
                        {
                            "UseClamd", Current.UseClamd
                        },
                        {
                            "ClamdHost", Current.ClamdHost
                        },
                        {
                            "ClamdPort", Current.ClamdPort
                        },
                        {
                            "ClamdIsLocal", Current.ClamdIsLocal
                        },
                        {
                            "UseVirusTotal", Current.UseVirusTotal
                        },
                        {
                            "VirusTotalKey", Current.VirusTotalKey
                        }
                    };

                    string preferencesPath =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library",
                                     "Preferences");

                    string preferencesFilePath =
                        Path.Combine(preferencesPath, "com.claunia.museum.apprepodbmgr.plist");

                    var fs = new FileStream(preferencesFilePath, FileMode.Create);
                    BinaryPropertyListWriter.Write(fs, root);
                    fs.Close();
                }

                break;

                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                case PlatformID.WindowsPhone:
                {
                    RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true)?.
                                            CreateSubKey("Canary Islands Computer Museum");

                    RegistryKey key = parentKey?.CreateSubKey("AppRepoDBMgr");

                    if (key != null)
                    {
                        key.SetValue("TemporaryFolder", Current.TemporaryFolder);
                        key.SetValue("DatabasePath", Current.DatabasePath);
                        key.SetValue("RepositoryPath", Current.RepositoryPath);

                        if (Current.UnArchiverPath != null)
                        {
                            key.SetValue("UnArchiverPath", Current.UnArchiverPath);
                        }

                        key.SetValue("CompressionAlgorithm", Current.CompressionAlgorithm);
                        key.SetValue("UseAntivirus", Current.UseAntivirus);
                        key.SetValue("UseClamd", Current.UseClamd);
                        key.SetValue("ClamdHost", Current.ClamdHost == null ? "" : Current.ClamdHost);
                        key.SetValue("ClamdPort", Current.ClamdPort);
                        key.SetValue("ClamdIsLocal", Current.ClamdIsLocal);
                        key.SetValue("UseVirusTotal", Current.UseVirusTotal);
                        key.SetValue("VirusTotalKey", Current.VirusTotalKey == null ? "" : Current.VirusTotalKey);
                    }
                }

                break;

                default:
                {
                    string configPath =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config");

                    string settingsPath = Path.Combine(configPath, "AppRepoDBMgr.xml");

                    if (!Directory.Exists(configPath))
                    {
                        Directory.CreateDirectory(configPath);
                    }

                    var fs = new FileStream(settingsPath, FileMode.Create);
                    var xs = new XmlSerializer(Current.GetType());
                    xs.Serialize(fs, Current);
                    fs.Close();
                }

                break;
                }
            }
            #pragma warning disable RECS0022     // A catch clause that catches System.Exception and has an empty body
            catch
                #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
            {
                if (Debugger.IsAttached)
                {
                    throw;
                }
            }
        }
Exemplo n.º 4
0
        public static void SaveSettings()
        {
            try
            {
                PlatformID ptId = DetectOS.GetRealPlatformID();

                switch (ptId)
                {
                // In case of macOS or iOS settings will be saved in ~/Library/Preferences/com.claunia.discimagechef.plist
                case PlatformID.MacOSX:
                case PlatformID.iOS:
                {
                    NSDictionary root = new NSDictionary
                    {
                        { "SaveReportsGlobally", Current.SaveReportsGlobally },
                        { "ShareReports", Current.ShareReports },
                        { "GdprCompliance", Current.GdprCompliance }
                    };
                    if (Current.Stats != null)
                    {
                        NSDictionary stats = new NSDictionary
                        {
                            { "ShareStats", Current.Stats.ShareStats },
                            { "BenchmarkStats", Current.Stats.BenchmarkStats },
                            { "CommandStats", Current.Stats.CommandStats },
                            { "DeviceStats", Current.Stats.DeviceStats },
                            { "FilesystemStats", Current.Stats.FilesystemStats },
                            { "FilterStats", Current.Stats.FilterStats },
                            { "MediaImageStats", Current.Stats.MediaImageStats },
                            { "MediaScanStats", Current.Stats.MediaScanStats },
                            { "PartitionStats", Current.Stats.PartitionStats },
                            { "MediaStats", Current.Stats.MediaStats },
                            { "VerifyStats", Current.Stats.VerifyStats }
                        };
                        root.Add("Stats", stats);
                    }

                    string preferencesPath =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library",
                                     "Preferences");
                    string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.discimagechef.plist");

                    FileStream fs = new FileStream(preferencesFilePath, FileMode.Create);
                    BinaryPropertyListWriter.Write(fs, root);
                    fs.Close();
                }
                break;

#if !NETSTANDARD2_0
                // In case of Windows settings will be saved in the registry: HKLM/SOFTWARE/Claunia.com/DiscImageChef
                case PlatformID.Win32NT:
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.WinCE:
                case PlatformID.WindowsPhone:
                {
                    RegistryKey parentKey =
                        Registry.CurrentUser.OpenSubKey("SOFTWARE", true)?.CreateSubKey("Claunia.com");
                    RegistryKey key = parentKey?.CreateSubKey("DiscImageChef");

                    if (key != null)
                    {
                        key.SetValue("SaveReportsGlobally", Current.SaveReportsGlobally);
                        key.SetValue("ShareReports", Current.ShareReports);
                        key.SetValue("GdprCompliance", Current.GdprCompliance);

                        if (Current.Stats != null)
                        {
                            key.SetValue("Statistics", true);
                            key.SetValue("ShareStats", Current.Stats.ShareStats);
                            key.SetValue("BenchmarkStats", Current.Stats.BenchmarkStats);
                            key.SetValue("CommandStats", Current.Stats.CommandStats);
                            key.SetValue("DeviceStats", Current.Stats.DeviceStats);
                            key.SetValue("FilesystemStats", Current.Stats.FilesystemStats);
                            key.SetValue("FilterStats", Current.Stats.FilterStats);
                            key.SetValue("MediaImageStats", Current.Stats.MediaImageStats);
                            key.SetValue("MediaScanStats", Current.Stats.MediaScanStats);
                            key.SetValue("PartitionStats", Current.Stats.PartitionStats);
                            key.SetValue("MediaStats", Current.Stats.MediaStats);
                            key.SetValue("VerifyStats", Current.Stats.VerifyStats);
                        }
                        else
                        {
                            key.SetValue("Statistics", true);
                            key.DeleteValue("ShareStats", false);
                            key.DeleteValue("BenchmarkStats", false);
                            key.DeleteValue("CommandStats", false);
                            key.DeleteValue("DeviceStats", false);
                            key.DeleteValue("FilesystemStats", false);
                            key.DeleteValue("MediaImageStats", false);
                            key.DeleteValue("MediaScanStats", false);
                            key.DeleteValue("PartitionStats", false);
                            key.DeleteValue("MediaStats", false);
                            key.DeleteValue("VerifyStats", false);
                        }
                    }
                }
                break;
#endif
                // Otherwise, settings will be saved in ~/.config/DiscImageChef.xml
                default:
                {
                    string homePath      = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                    string xdgConfigPath =
                        Path.Combine(homePath,
                                     Environment.GetEnvironmentVariable(XDG_CONFIG_HOME) ??
                                     XDG_CONFIG_HOME_RESOLVED);
                    string settingsPath = Path.Combine(xdgConfigPath, "DiscImageChef.xml");

                    if (!Directory.Exists(xdgConfigPath))
                    {
                        Directory.CreateDirectory(xdgConfigPath);
                    }

                    FileStream    fs = new FileStream(settingsPath, FileMode.Create);
                    XmlSerializer xs = new XmlSerializer(Current.GetType());
                    xs.Serialize(fs, Current);
                    fs.Close();
                }
                break;
                }
            }
            #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
            catch
            {
                // ignored
            }
            #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
        }
 public byte[] WriteLargePropertylistTest()
 {
     return(BinaryPropertyListWriter.WriteToArray(data));
 }
Exemplo n.º 6
0
        public static void SaveSettings()
        {
            try
            {
                PlatformID ptId = DetectOS.GetRealPlatformID();

                switch (ptId)
                {
                // In case of macOS or iOS settings will be saved in ~/Library/Preferences/com.claunia.romrepomgr.plist
                case PlatformID.MacOSX:
                case PlatformID.iOS:
                {
                    var root = new NSDictionary
                    {
                        {
                            "DatabasePath", Current.DatabasePath
                        },
                        {
                            "RepositoryPath", Current.RepositoryPath
                        },
                        {
                            "TemporaryFolder", Current.TemporaryFolder
                        },
                        {
                            "UnArchiverPath", Current.UnArchiverPath
                        }
                    };

                    string preferencesPath =
                        Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library",
                                     "Preferences");

                    string preferencesFilePath = Path.Combine(preferencesPath, "com.claunia.romrepomgr.plist");

                    var fs = new FileStream(preferencesFilePath, FileMode.Create);
                    BinaryPropertyListWriter.Write(fs, root);
                    fs.Close();
                }

                break;

                #if !NETSTANDARD2_0
                // In case of Windows settings will be saved in the registry: HKLM/SOFTWARE/Claunia.com/RomRepoMgr
                case PlatformID.Win32NT when OperatingSystem.IsWindows():
                case PlatformID.Win32S when OperatingSystem.IsWindows():
                case PlatformID.Win32Windows when OperatingSystem.IsWindows():
                case PlatformID.WinCE when OperatingSystem.IsWindows():
                case PlatformID.WindowsPhone when OperatingSystem.IsWindows():
                {
                    RegistryKey parentKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true)?.
                                            CreateSubKey("Claunia.com");

                    RegistryKey key = parentKey?.CreateSubKey("RomRepoMgr");

                    key?.SetValue("DatabasePath", Current.DatabasePath);
                    key?.SetValue("RepositoryPath", Current.RepositoryPath);
                    key?.SetValue("TemporaryFolder", Current.TemporaryFolder);
                    key?.SetValue("UnArchiverPath", Current.UnArchiverPath);
                }

                break;
                #endif

                // Otherwise, settings will be saved in ~/.config/RomRepoMgr.json
                default:
                {
                    string homePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

                    string xdgConfigPath =
                        Path.Combine(homePath,
                                     Environment.GetEnvironmentVariable(XDG_CONFIG_HOME) ??
                                     XDG_CONFIG_HOME_RESOLVED);

                    string settingsPath = Path.Combine(xdgConfigPath, "RomRepoMgr.json");

                    if (!Directory.Exists(xdgConfigPath))
                    {
                        Directory.CreateDirectory(xdgConfigPath);
                    }

                    var prefsSr = new StreamWriter(settingsPath);

                    prefsSr.Write(JsonSerializer.Serialize(Current, new JsonSerializerOptions
                        {
                            AllowTrailingCommas         = true,
                            PropertyNameCaseInsensitive = true,
                            ReadCommentHandling         = JsonCommentHandling.Skip,
                            WriteIndented = true
                        }));

                    prefsSr.Close();
                }

                break;
                }
            }
            #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
            catch
            {
                // ignored
            }
            #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
        }