private async void CheckForIpcFile() { var ipcPath = Path.Combine(AppData.Path, "ipc.dat"); while (_isRunning) { try { if (File.Exists(ipcPath)) { var lines = File.ReadAllLines(ipcPath); File.Delete(ipcPath); foreach (var contents in lines) { NexusUrl url; if (NexusUrl.TryParse(contents, out url)) { HandleUrl(url); } } } } catch { } await Task.Delay(1000); } }
//process the arguments passed into the application public static void ProcessArgs(string[] args) { var options = new AppCommandLineOptions(); Parser.Default.ParseArguments(args, options); foreach (var t in args) { if (t.Contains("parkitectnexus://")) { options.Url = t; } } if (args.Any()) { Parser.Default.ParseArguments(args, options); if (options.Url != null) { NexusUrl url; if (NexusUrl.TryParse(options.Url, out url)) { App.HandleUrl(url); } } } }
public void TryParseInstallTest() { // arrange string url1 = "parkitectnexus://install/testidentifier"; // act var result1 = NexusUrl.Parse(url1); Assert.True(UrlAction.Install == result1.Action); Assert.IsInstanceOf(typeof(InstallUrlAction), result1.Data); Assert.AreEqual("testidentifier", (result1.Data as InstallUrlAction)?.Id); }
public void TryParseAuthTest() { // arrange string url1 = "parkitectnexus://auth/myauthkey"; // act var result1 = NexusUrl.Parse(url1); Assert.AreEqual(UrlAction.Auth, result1.Action); Assert.IsInstanceOfType(result1.Data, typeof(AuthUrlAction)); Assert.AreEqual("myauthkey", (result1.Data as AuthUrlAction)?.Key); }
public async Task CreateMod(Game CurrentGame, NexusUrl nexusUrl) //online { if (!_db.GetCollection <Mod>("mods").Exists(x => x.FileId == nexusUrl.FileId) && _accountHandler.IsLoggedIn) { var result_downloadInfo = await _nexusCommunicator.GetDownloadLinks(CurrentGame.Name_API, nexusUrl.ModId, nexusUrl.FileId); var result_modInfo = await _nexusCommunicator.GetModInfo(CurrentGame.Name_API, nexusUrl.ModId); var result_fileInfo = await _nexusCommunicator.GetModFileInfo(CurrentGame.Name_API, nexusUrl.ModId, nexusUrl.FileId); string ModDownloadTo = $@"{CurrentGame.DownloadsDirectory }\{result_modInfo.name}"; if (!Directory.Exists(ModDownloadTo)) { Directory.CreateDirectory(ModDownloadTo); } string DownloadTo = $@"{ModDownloadTo}\{ result_fileInfo.name.Split('-').LastOrDefault().Trim(' ')}"; string DownloadAs = DownloadTo + $@"\{result_fileInfo.file_name}"; string InstallTo = $@"{CurrentGame.ModsDirectory}\{result_modInfo.name} [{result_fileInfo.name}]"; if (!Directory.Exists(DownloadTo)) { Directory.CreateDirectory(DownloadTo); } if (!Directory.Exists(InstallTo)) { Directory.CreateDirectory(InstallTo); } if (File.Exists(DownloadAs)) { File.Delete(DownloadAs); } Mod newMod = new Mod(result_modInfo.name, result_fileInfo.name, false, true, DownloadAs, InstallTo, DownloadTo, CurrentGame.Id, (ModCategories)result_modInfo.category_id, nexusUrl.FileId, ModControls.Count, result_modInfo.version, nexusUrl.ModId, result_modInfo.author, nexusUrl.SourceUrl.ToString(), true); await Task.Run(async() => { await DownloadsManager.AddDownload(new Uri(result_downloadInfo.URI), DownloadAs, DownloadTo, InstallTo, result_modInfo.name, result_fileInfo.name, newMod); }); } }
static void Main(string[] args) { var registry = ObjectFactory.ConfigureStructureMap(); registry.IncludeRegistry(new PresenterRegistry()); registry.For <IApp>().Singleton().Use <App>(); ObjectFactory.SetUpContainer(registry); var presenterFactory = ObjectFactory.GetInstance <IPresenterFactory>(); var app = presenterFactory.InstantiatePresenter <App>(); if (!app.Initialize(ToolkitType.Cocoa)) { return; } MacEngine.App.OpenUrl += (sender, e) => { ObjectFactory.GetInstance <ILogger>().WriteLine($"Got url {e.Url}"); if (e.Url.StartsWith("parkitectnexus://")) { e.Url = e.Url; } else { var match = Regex.Match(e.Url, "<NSAppleEventDescriptor: \"(parkitectnexus:\\/\\/.*)\">"); if (match.Success) { e.Url = match.Groups[1].Value; } } NexusUrl url; if (NexusUrl.TryParse(e.Url, out url)) { app.HandleUrl(url); } }; TmpFixModLoaderUtil.InstallModLoader(ObjectFactory.GetInstance <IParkitect>(), ObjectFactory.GetInstance <ILogger>()); app.Run(); }
private IEnumerable <Tile> LoadTiles() { yield return(CreateTile("Visit ParkitectNexus", App.DImages["parkitectnexus_logo-64x64.png"], Color.FromBytes(0xf3, 0x77, 0x35), _website.Launch)); if (OperatingSystem.Detect() == SupportedOperatingSystem.Linux) { yield return (CreateTile("Download URL", App.DImages["appbar.browser.wire.png"], Color.FromBytes(0xf3, 0x77, 0x35), () => { var entry = new TextEntry(); var box = new HBox(); box.PackStart(new Label("URL:")); box.PackStart(entry, true, true); var dialog = new Dialog { Width = 300, Icon = ParentWindow.Icon, Title = "Enter URL to download", Content = box }; dialog.Buttons.Add(new DialogButton(Command.Cancel)); dialog.Buttons.Add(new DialogButton(Command.Ok)); var result = dialog.Run(ParentWindow); NexusUrl url; if (result.Label.ToLower() == "ok" && NexusUrl.TryParse(entry.Text, out url)) { ObjectFactory.GetInstance <IApp>().HandleUrl(url); } dialog.Dispose(); })); } yield return (CreateTile("Launch Parkitect", App.DImages["parkitect_logo.png"], Color.FromBytes(45, 137, 239), () => { _parkitect.Launch(); })); yield return(CreateTile("Help", App.DImages["appbar.information.png"], Color.FromBytes(45, 137, 239), () => { // Temporary help solution. Process.Start( "https://parkitectnexus.com/forum/2/parkitectnexus-website-client/70/troubleshooting-mods-and-client"); })); yield return(CreateTile("Donate!", App.DImages["appbar.thumbs.up.png"], Color.FromBytes(45, 137, 239), () => { if (MessageDialog.AskQuestion("Maintaining this client and adding new features takes a lot of time.\n" + "If you appreciate our work, please consider sending a donation our way!\n" + "All donations will be used for further development of the ParkitectNexus Client and the website.\n" + "\nSelect Yes to visit PayPal and send a donation.", 1, Command.No, Command.Yes) == Command.Yes) { Process.Start("https://paypal.me/ikkentim"); } })); }
void App_Startup(object sender, StartupEventArgs e) { NexusUrl modArg = null; bool isMainProcess = false; _dbProfiles = new List <DatabaseContext_Profile>(); _mutex = new Mutex(false, "Global\\" + appGuid); try { isMainProcess = _mutex.WaitOne(0, false); } catch (Exception) { isMainProcess = false; } // Application is running // Process command line args bool startMinimized = false; for (int i = 0; i < e.Args.Length; ++i) { if (e.Args[i] == "/StartMinimized") { startMinimized = true; } else { try { modArg = new NexusUrl(new Uri(e.Args[i])); } catch (Exception) { Current.Shutdown(); } } } if (!isMainProcess) { _mutex.ReleaseMutex(); _mutex.Close(); if (modArg != null) { ProcessStartInfo info = new ProcessStartInfo(Defined.NAMED_PIPE_CLIENT_EXECUTABLE) { Arguments = modArg.ToString(), CreateNoWindow = true }; Process.Start(info); Current.Shutdown(); } } else { _namedPipeManager = new NamedPipeManager(); _jsonParser = new Service_JsonParser(); RequiredDirectories = new string[] { Defined.Settings.ApplicationDataPath }; foreach (var item in RequiredDirectories) { if (!Directory.Exists(item)) { Directory.CreateDirectory(item); } } _db = new DatabaseContext_Main();// Strong Type Class foreach (var game in _db.GetCollection <Game>("games").FindAll()) { if (!Directory.Exists(game.ModsDirectory)) { Directory.CreateDirectory(game.ModsDirectory); } if (!Directory.Exists(game.DownloadsDirectory)) { Directory.CreateDirectory(game.DownloadsDirectory); } if (!Directory.Exists(game.ProfilesDirectory)) { Directory.CreateDirectory(game.ProfilesDirectory); } } _profilesManager = new ProfilesManager(_db); foreach (var item in _db.GetCollection <Classes.DatabaseClasses.UserProfile>("profiles").FindAll()) { _dbProfiles.Add(new DatabaseContext_Profile(item.ProfileDirectory, item.GameId)); } if (Defined.Settings.State == StatesOfConfiguration.FirstTime || _db.GetCollection <Game>("games").FindAll().Count() < 1) { _db.FirstTimeSetup(_mutex, _jsonParser, _namedPipeManager, _dbProfiles, _profilesManager); foreach (var item in _dbProfiles) { item.FirstTimeSetup(); } return; } else if (Defined.Settings.State == StatesOfConfiguration.Ready) { // Create main application window, starting minimized if specified MainWindow mainWindow = new MainWindow(_mutex, _db, _jsonParser, _namedPipeManager, _dbProfiles, _profilesManager, modArg); if (startMinimized) { mainWindow.WindowState = WindowState.Minimized; } mainWindow.Show(); mainWindow.InitBindings(); } } }
public static void Main(string[] args) { // Look and see if this is the only running instance of the client. var procCount = #if !DEBUG Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName) .Count(p => p.MainModule.FileName == Process.GetCurrentProcess().MainModule.FileName); #else Process.GetProcesses().Count(p => p.ProcessName.Contains("ParkitectNexus")); #endif if (procCount == 1) { // No matter if the application crashes, we must release the mutex when the app closes. Wrap the app // logic in a try-finally block. #if !DEBUG try { #endif // Initialize the structure map container. var registry = ObjectFactory.ConfigureStructureMap(); registry.IncludeRegistry(new PresenterRegistry()); registry.For <IApp>().Singleton().Use <App>(); ObjectFactory.SetUpContainer(registry); // Create the form and run its message loop. If arguments were specified, process them within the // form. var presenterFactory = ObjectFactory.GetInstance <IPresenterFactory>(); var app = presenterFactory.InstantiatePresenter <App>(); if (!app.Initialize(ToolkitType.Wpf)) { return; } ParkitectNexusProtocol.Install(ObjectFactory.GetInstance <ILogger>()); if (args.Any()) { var options = new AppCommandLineOptions(); Parser.Default.ParseArguments(args, options); if (options.Url != null) { NexusUrl url; if (NexusUrl.TryParse(options.Url, out url)) { app.HandleUrl(url); } } } app.Run(); #if !DEBUG } catch (Exception e) { // Report crash to the server. var crashReporterFactory = ObjectFactory.GetInstance <ICrashReporterFactory>(); crashReporterFactory.Report("global", e); // Write the error to the log file. var log = ObjectFactory.GetInstance <ILogger>(); log?.WriteLine("Application crashed!", LogLevel.Fatal); log?.WriteException(e); } #endif return; } // If any arguments are set, pass these on to our main application instance. if (args.Any()) { var attempts = 0; do { try { // Write the specified arguments to a temporary ipc.dat file. using (var fileStream = File.OpenWrite(Path.Combine(AppData.Path, "ipc.dat"))) using (var streamWriter = new StreamWriter(fileStream)) { var options = new AppCommandLineOptions(); Parser.Default.ParseArguments(args, options); if (options.Url != null) { streamWriter.WriteLine(options.Url); } } return; } catch (IOException) { // If storing the arguments fails, we're in trouble. Let's try it again in a few. Thread.Sleep(500); attempts++; } } while (attempts < 5); // Limit to 5 attempts. } }