예제 #1
0
        public static void Write(string file, string folder, BinaryWriterStreamConsumer callback)
        {
            TransactedIO.WriteStream(file, folder, stream =>
            {
#if NET35
                using var ms = new MemoryStream();
                using var w  = new BinaryWriter(ms);
#else
                using var w = new BinaryWriter(stream, Encoding.UTF8, true);
#endif
                callback(w);
#if NET35
                ms.CopyTo(stream);
#endif
            });
        }
예제 #2
0
        public static void Read(string file, string folder, BinaryReaderStreamConsumer callback)
        {
            if (!TransactedIO.ReadStream(file, folder, stream =>
            {
#if NET35
                using var ms = new MemoryStream();
                stream.CopyTo(ms);
                using var r = new BinaryReader(ms);
                callback(r);
#else
                using var r = new BinaryReader(stream, Encoding.UTF8, true);
                callback(r);
#endif
            }))
            {
                throw new IOException(Path.Combine(Config.DataDir, file));
            }
        }
예제 #3
0
        public static void SerializeConfig()
        {
            var instance = Config.Instance;

            using var ms = new MemoryStream();
            using var w  = new BinaryWriter(ms);

            w.Write((short)(instance.Proxy.HasValue ? 36 : 35)); //total fields

            WriteString(w, instance.AfterCompletionCommand, "AfterCompletionCommand");
            WriteString(w, instance.UserSelectedDownloadFolder, "UserSelectedDownloadFolder");
            WriteString(w, instance.AntiVirusArgs, "AntiVirusArgs");
            WriteString(w, instance.AntiVirusExecutable, "AntiVirusExecutable");
            WriteString(w, instance.DefaultDownloadFolder, "DefaultDownloadFolder");
            WriteString(w, instance.Language, "Language");
            WriteString(w, instance.TempDir, "TempDir");

            WriteBoolean(w, instance.EnableSpeedLimit, "EnableSpeedLimit");
            WriteBoolean(w, instance.FetchServerTimeStamp, "FetchServerTimeStamp");
            WriteBoolean(w, instance.IsBrowserMonitoringEnabled, "IsBrowserMonitoringEnabled");
            WriteBoolean(w, instance.KeepPCAwake, "KeepPCAwake");
            WriteBoolean(w, instance.MonitorClipboard, "MonitorClipboard");
            WriteBoolean(w, instance.RunCommandAfterCompletion, "RunCommandAfterCompletion");
            //WriteBoolean(w, instance.RunOnLogon, "RunOnLogon");
            WriteBoolean(w, instance.ScanWithAntiVirus, "ScanWithAntiVirus");
            WriteBoolean(w, instance.ShowDownloadCompleteWindow, "ShowDownloadCompleteWindow");
            WriteBoolean(w, instance.ShowProgressWindow, "ShowProgressWindow");
            WriteBoolean(w, instance.ShutdownAfterAllFinished, "ShutdownAfterAllFinished");
            WriteBoolean(w, instance.StartDownloadAutomatically, "StartDownloadAutomatically");
            WriteBoolean(w, instance.AllowSystemDarkTheme, "AllowSystemDarkTheme");
            WriteBoolean(w, instance.DoubleClickOpenFile, "DoubleClickOpenFile");

            WriteInt32(w, (int)instance.FileConflictResolution, "FileConflictResolution");
            WriteInt32(w, (int)instance.FolderSelectionMode, "FolderSelectionMode");

            WriteInt32(w, instance.DefaltDownloadSpeed, "DefaltDownloadSpeed");
            WriteInt32(w, instance.MaxParallelDownloads, "MaxParallelDownloads");
            WriteInt32(w, instance.MaxRetry, "MaxRetry");
            WriteInt32(w, instance.MaxSegments, "MaxSegments");
            WriteInt32(w, instance.MinVideoSize, "MinVideoSize");
            WriteInt32(w, instance.NetworkTimeout, "NetworkTimeout");
            WriteInt32(w, instance.RetryDelay, "RetryDelay");

            WriteStringArray(w, instance.BlockedHosts, "BlockedHosts", instance.BlockedHosts.Length);
            WriteStringArray(w, instance.FileExtensions, "FileExtensions", instance.FileExtensions.Length);
            WriteStringArray(w, instance.RecentFolders, "RecentFolders", instance.RecentFolders.Count);
            WriteStringArray(w, instance.VideoExtensions, "VideoExtensions", instance.VideoExtensions.Length);

            w.Write("Categories");
            w.Write(OBJECT_ARRAY);
            w.Write((short)instance.Categories.Count());
            w.Write((short)5); //no of fields in Category class
            foreach (var cat in instance.Categories)
            {
                WriteString(w, cat.DefaultFolder, "DefaultFolder");
                WriteString(w, cat.DisplayName, "DisplayName");
                WriteBoolean(w, cat.IsPredefined, "IsPredefined");
                WriteString(w, cat.Name, "Name");
                WriteStringArray(w, cat.FileExtensions, "FileExtensions", cat.FileExtensions.Count);
            }

            w.Write("UserCredentials");
            w.Write(OBJECT_ARRAY);
            w.Write((short)instance.UserCredentials.Count());
            w.Write((short)3); //no of fields in Category class
            foreach (var pe in instance.UserCredentials)
            {
                WriteString(w, pe.Host, "Host");
                WriteString(w, pe.User, "User");
                WriteString(w, pe.Password, "Password");
            }

            if (instance.Proxy.HasValue)
            {
                ProxyInfoSerializer.Serialize(instance.Proxy.Value, w);
            }

            w.Close();
            ms.Close();
            TransactedIO.WriteBytes(ms.ToArray(), "settings.dat", Config.DataDir);
        }