private FamiliarCommandLineArguments ResolveArguments(CommandLineArgument[] parsedArgs) { var result = new FamiliarCommandLineArguments(); if (parsedArgs.Length == 0) { return(result); } CommandLineOption.ValidateMutuallyExclusive(parsedArgs, _testFileOpt, _connectOpt, _infoOpt, _helpOpt); _testFileOpt.ValidateThisForbidsOthers(parsedArgs, _selectOpt, _databaseOpt); _connectOpt.ValidateThisForbidsOthers(parsedArgs, _selectOpt); _infoOpt.ValidateThisForbidsOthers(parsedArgs, _selectOpt); _helpOpt.ValidateThisForbidsOthers(parsedArgs, _selectOpt, _databaseOpt); result.Verbose = _verboseOpt.ExtractOrNull(parsedArgs) != null; result.ShowHelp = _helpOpt.ExtractOrNull(parsedArgs) != null; result.TestFile = _testFileOpt.ExtractOrNull(parsedArgs)?.Value; result.Connect = _connectOpt.ExtractOrNull(parsedArgs)?.Value; result.ShowInfo = _infoOpt.ExtractOrNull(parsedArgs) != null; result.SelectWindow = _selectOpt.ExtractOrNull(parsedArgs) != null; result.Database = _databaseOpt.ExtractOrNull(parsedArgs)?.Value; return(result); }
private bool SelectWindow(FamiliarCommandLineArguments resolvedArgs, Process currentProcess, out int parentPid, out IntPtr targetWindow) { if (resolvedArgs.SelectWindow) { var attachSelector = new AttachSelector(); attachSelector.ShowDialog(); parentPid = attachSelector.ParentPid; targetWindow = attachSelector.TargetWindow; if (parentPid == 0) { Current.Shutdown(ExitCodes.UserCanceledAttach); return(false); } } else { parentPid = GetParentProcessId(currentProcess); var attached = Kernel32.AttachConsole((uint)parentPid); _trace.TraceVerbose("{0} returned {1}", nameof(Kernel32.AttachConsole), attached); targetWindow = Kernel32.GetConsoleWindow(); if (targetWindow == IntPtr.Zero) { _trace.TraceWarning("No console window detected."); MessageBox.Show("Console not detected.\r\nPlease, start the familiar from Command Prompt.", "Familiar Notification", MessageBoxButton.OK, MessageBoxImage.Information); Current.Shutdown(ExitCodes.ConsoleNotDetected); return(false); } } return(true); }
private void ConnectToSharedDir(FamiliarCommandLineArguments args) { var newSharedDir = new DirectoryInfo(Path.Combine(args.Connect, "familiar")); var config = Configuration.LoadDefault(args); if (config == null) { config = Configuration.CreateDefault(args); } if (config.SharedDirectory != null) { Terminal.WriteLine("Will change: {0}", config.SharedDirectory.FullName); Terminal.WriteLine(" To: {0}", newSharedDir.FullName); } else { Terminal.WriteLine("New shared directory: {0}", newSharedDir.FullName); } if (!newSharedDir.Exists) { Terminal.WriteLine("Directory does not exist. Please create if you want to use that."); return; } var configFile = config.ConfigFile; ConfigurationData configData; using (var stream = new FileStream(configFile.FullName, FileMode.Open)) { configData = Serializer.LoadFromStream <ConfigurationData>(stream); } configData.SharedFolder = newSharedDir.FullName; using (var stream = new FileStream(configFile.FullName, FileMode.Create)) { Serializer.SaveToStream(stream, configData); } var localStore = new FileStore(config); var myDataFile = localStore.FileName; var replication = new InboundReplication( newSharedDir, config.LocalDbDirectory, TimeSpan.Zero, (fileName) => !string.Equals(myDataFile, fileName, StringComparison.OrdinalIgnoreCase) ); replication.RunOnce(); Terminal.WriteLine("Done."); }
private void ShowInformation(FamiliarCommandLineArguments args) { var config = Configuration.LoadDefault(args); if (config == null) { Terminal.WriteLine("There is no active configuration."); return; } Terminal.WriteLine("Configuration file: {0}", config.ConfigFile.FullName); Terminal.WriteLine("Local data directory: {0}", config.LocalDbDirectory?.FullName ?? "not set"); Terminal.WriteLine("Shared data directory: {0}", config.SharedDirectory?.FullName ?? "not set"); Terminal.WriteLine("Session id: {0}", config.SessionId); Terminal.WriteLine(); }