Exemplo n.º 1
0
        public void GetDiskClusters(int diskSizeMiB, int expectedClusters, TOSVersion tosVersion)
        {
            AtariDiskSettings diskSettings = new AtariDiskSettings()
            {
                DiskSizeMiB          = diskSizeMiB,
                DiskTOSCompatibility = tosVersion,
                RootDirectorySectors = 8
            };

            diskParams = new DiskParameters(".", diskSettings, _logger.Object);

            int diskClusters = diskParams.DiskClusters;

            Assert.AreEqual(expectedClusters, diskClusters);
        }
Exemplo n.º 2
0
        public void GetSectorsPerFat(int diskSizeMiB, int expectedSectorsPerFat, TOSVersion tosVersion)
        {
            AtariDiskSettings diskSettings = new AtariDiskSettings()
            {
                DiskSizeMiB          = diskSizeMiB,
                DiskTOSCompatibility = tosVersion,
                RootDirectorySectors = 8
            };

            diskParams = new DiskParameters(".", diskSettings, _logger.Object);

            int sectorsPerFat = diskParams.SectorsPerFat;

            Assert.AreEqual(expectedSectorsPerFat, sectorsPerFat);
        }
Exemplo n.º 3
0
        public void GetBytesPerSector(int diskSizeMiB, int expectedBytesPerSector, TOSVersion tosVersion)
        {
            AtariDiskSettings diskSettings = new AtariDiskSettings()
            {
                DiskSizeMiB          = diskSizeMiB,
                DiskTOSCompatibility = tosVersion,
                RootDirectorySectors = 8
            };

            diskParams = new DiskParameters(".", diskSettings, _logger.Object);

            int bytesPerSector = diskParams.BytesPerSector;

            Assert.AreEqual(expectedBytesPerSector, bytesPerSector);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            var versionMessage = "Serial Disk v" + Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion;

            Console.WriteLine(versionMessage);

            #region Dependency injection

            var serviceCollection = new ServiceCollection();
            ConfigureServices(serviceCollection);
            var serviceProvider = serviceCollection.BuildServiceProvider();

            #endregion

            #region Application settings

            try
            {
                var defaultConfigResourceName = $"AtariST.SerialDisk.Resources.default_config_{OSHelper.OperatingSystemName.ToLower()}.json";

                using (var defaultConfigStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(defaultConfigResourceName))
                {
                    DataContractJsonSerializer appSettingsSerializer = new DataContractJsonSerializer(typeof(ApplicationSettings));
                    _applicationSettings = (ApplicationSettings)appSettingsSerializer.ReadObject(defaultConfigStream);
                }

                var configBuilder = new ConfigurationBuilder();

                configBuilder.AddJsonFile("serialdisk.config", true, false)
                .Build()
                .Bind(_applicationSettings);

                if (args.Any() && args.Where(arg => arg.ToLowerInvariant().StartsWith("--help")).Any())
                {
                    PrintUsage(_applicationSettings);
                    return;
                }

                configBuilder.AddCommandLine(args, Constants.ConsoleParameterMappings)
                .Build()
                .Bind(_applicationSettings);

                _applicationSettings.LocalDirectoryPath = ParseLocalDirectoryPath(_applicationSettings.LocalDirectoryPath, args);
            }

            catch (Exception parameterException)
            {
                Console.WriteLine($"Error parsing parameters: {parameterException.Message}");
                return;
            }


            if (String.IsNullOrEmpty(_applicationSettings.LocalDirectoryPath) ||
                !Directory.Exists(_applicationSettings.LocalDirectoryPath))
            {
                Console.WriteLine($"Local directory path {_applicationSettings.LocalDirectoryPath} not found.");
                return;
            }

            #endregion

            _logger = new Logger(_applicationSettings.LoggingLevel, _applicationSettings.LogFileName);

            _logger.LogToFile(versionMessage);

            var json = JsonSerializer.Serialize(_applicationSettings, typeof(ApplicationSettings));

            _logger.Log(json, LoggingLevel.All);

            _logger.Log($"Operating system: {System.Runtime.InteropServices.RuntimeInformation.OSArchitecture} {System.Runtime.InteropServices.RuntimeInformation.OSDescription}", LoggingLevel.Debug);
            _logger.Log($"Framework version: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}", LoggingLevel.Debug);

            _diskParameters = new DiskParameters(_applicationSettings.LocalDirectoryPath, _applicationSettings.DiskSettings, _logger);

            _logger.Log($"Importing local directory contents from {_applicationSettings.LocalDirectoryPath}", Constants.LoggingLevel.Debug);

            _disk = new Disk(_diskParameters, _logger);

            CancellationTokenSource cancelTokenSource = new CancellationTokenSource();

            _serial = new Serial(_applicationSettings.SerialSettings, _disk, _logger, cancelTokenSource, _applicationSettings.IsCompressionEnabled);

            _logger.Log($"Baud rate:{_applicationSettings.SerialSettings.BaudRate} | Data bits:{_applicationSettings.SerialSettings.DataBits}" +
                        $" | Parity:{_applicationSettings.SerialSettings.Parity} | Stop bits:{_applicationSettings.SerialSettings.StopBits} | Flow control:{_applicationSettings.SerialSettings.Handshake}", LoggingLevel.Info);
            _logger.Log($"Using local directory {_applicationSettings.LocalDirectoryPath} as a {_applicationSettings.DiskSettings.DiskSizeMiB}MiB virtual disk", LoggingLevel.Info);
            _logger.Log($"Compression: " + (_applicationSettings.IsCompressionEnabled ? "Enabled" : "Disabled"), LoggingLevel.Info);
            _logger.Log($"Logging level: { _applicationSettings.LoggingLevel} ", LoggingLevel.Info);

            Console.WriteLine("Press Ctrl-X to quit, Ctrl-R to reimport local disk content.");

            Task keyboardListener = ListenForConsoleKeypress();

            try
            {
                keyboardListener.Wait(cancelTokenSource.Token);
            }

            catch (OperationCanceledException ex)
            {
                _logger.Log("Thread cancellation requested", LoggingLevel.Debug);
                _logger.Log(ex.Message, LoggingLevel.Debug);
            }

            _serial.Dispose();
            _logger.Dispose();

            Console.ResetColor();
        }