public bool Merge(PathMatcher matcher) { var merge = false; if (isFolder && matcher.isFolder) { if (BasePath.StartsWith(matcher.BasePath)) { BasePath = matcher.BasePath; merge = true; } else if (matcher.BasePath.StartsWith(BasePath)) { merge = true; } if (merge) { extensionPatterns = extensionPatterns.Union(matcher.extensionPatterns).Distinct().ToArray(); regexes = matcher.RegexesInternal.Union(RegexesInternal).ToArray(); } } return(merge); }
public void Configure( IApplicationBuilder app, IWebHostEnvironment env, IApiVersionDescriptionProvider provider, ITransferTracker tracker, IBrowseTracker browseTracker, IConversationTracker conversationTracker, IRoomTracker roomTracker) { if (!env.IsDevelopment()) { app.UseHsts(); } app.UseCors("AllowAll"); BasePath = BasePath ?? "/"; BasePath = BasePath.StartsWith("/") ? BasePath : $"/{BasePath}"; app.UsePathBase(BasePath); // remove any errant double forward slashes which may have been introduced // by a reverse proxy or having the base path removed app.Use(async(context, next) => { var path = context.Request.Path.ToString(); if (path.StartsWith("//")) { context.Request.Path = new string(path.Skip(1).ToArray()); } await next(); }); WebRoot = WebRoot ?? Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).AbsolutePath), "wwwroot"); Console.WriteLine($"Serving static content from {WebRoot}"); var fileServerOptions = new FileServerOptions { FileProvider = new PhysicalFileProvider(WebRoot), RequestPath = "", EnableDirectoryBrowsing = false, EnableDefaultFiles = true }; app.UseFileServer(fileServerOptions); app.UseAuthentication(); app.UseMvc(); app.UseSwagger(); app.UseSwaggerUI(options => provider.ApiVersionDescriptions.ToList() .ForEach(description => options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName))); // if we made it this far and the route still wasn't matched, return the index // this is required so that SPA routing (React Router, etc) can work properly app.Use(async(context, next) => { // exclude API routes which are not matched or return a 404 if (!context.Request.Path.StartsWithSegments("/api")) { context.Request.Path = "/"; } await next(); }); app.UseFileServer(fileServerOptions); // --------------------------------------------------------------------------------------------------------------------------------------------- // begin SoulseekClient implementation // --------------------------------------------------------------------------------------------------------------------------------------------- var connectionOptions = new ConnectionOptions( readBufferSize: ReadBufferSize, writeBufferSize: WriteBufferSize, connectTimeout: ConnectTimeout, inactivityTimeout: InactivityTimeout); // create options for the client. // see the implementation of Func<> and Action<> options for detailed info. var clientOptions = new SoulseekClientOptions( listenPort: ListenPort, userEndPointCache: new UserEndPointCache(), distributedChildLimit: DistributedChildLimit, enableDistributedNetwork: EnableDistributedNetwork, minimumDiagnosticLevel: DiagnosticLevel, autoAcknowledgePrivateMessages: false, serverConnectionOptions: connectionOptions, peerConnectionOptions: connectionOptions, transferConnectionOptions: connectionOptions, userInfoResponseResolver: UserInfoResponseResolver, browseResponseResolver: BrowseResponseResolver, directoryContentsResponseResolver: DirectoryContentsResponseResolver, enqueueDownloadAction: (username, endpoint, filename) => EnqueueDownloadAction(username, endpoint, filename, tracker), searchResponseResolver: SearchResponseResolver); Client = new SoulseekClient(options: clientOptions); // bind the DiagnosticGenerated event so we can trap and display diagnostic messages. this is optional, and if the event // isn't bound the minimumDiagnosticLevel should be set to None. Client.DiagnosticGenerated += (e, args) => { lock (ConsoleSyncRoot) { if (args.Level == DiagnosticLevel.Debug) { Console.ForegroundColor = ConsoleColor.DarkGray; } if (args.Level == DiagnosticLevel.Warning) { Console.ForegroundColor = ConsoleColor.Yellow; } Console.WriteLine($"[{DateTime.Now:HH:mm:ss.fff}] [DIAGNOSTIC:{e.GetType().Name}] [{args.Level}] {args.Message}"); Console.ResetColor(); } }; // bind transfer events. see TransferStateChangedEventArgs and TransferProgressEventArgs. Client.TransferStateChanged += (e, args) => { var direction = args.Transfer.Direction.ToString().ToUpper(); var user = args.Transfer.Username; var file = Path.GetFileName(args.Transfer.Filename); var oldState = args.PreviousState; var state = args.Transfer.State; var completed = args.Transfer.State.HasFlag(TransferStates.Completed); Console.WriteLine($"[{direction}] [{user}/{file}] {oldState} => {state}{(completed ? $" ({args.Transfer.BytesTransferred}/{args.Transfer.Size} = {args.Transfer.PercentComplete}%) @ {args.Transfer.AverageSpeed.SizeSuffix()}/s" : string.Empty)}"); }; Client.TransferProgressUpdated += (e, args) => { // this is really verbose. // Console.WriteLine($"[{args.Transfer.Direction.ToString().ToUpper()}] [{args.Transfer.Username}/{Path.GetFileName(args.Transfer.Filename)}] {args.Transfer.BytesTransferred}/{args.Transfer.Size} {args.Transfer.PercentComplete}% {args.Transfer.AverageSpeed}kb/s"); }; // bind BrowseProgressUpdated to track progress of browse response payload transfers. // these can take a while depending on number of files shared. Client.BrowseProgressUpdated += (e, args) => { browseTracker.AddOrUpdate(args.Username, args); }; // bind UserStatusChanged to monitor the status of users added via AddUserAsync(). Client.UserStatusChanged += (e, args) => { // Console.WriteLine($"[USER] {args.Username}: {args.Status}"); }; Client.PrivateMessageReceived += (e, args) => { conversationTracker.AddOrUpdate(args.Username, PrivateMessage.FromEventArgs(args)); }; Client.RoomMessageReceived += (e, args) => { var message = RoomMessage.FromEventArgs(args, DateTime.UtcNow); roomTracker.AddOrUpdateMessage(args.RoomName, message); }; Client.RoomJoined += (e, args) => { if (args.Username != Username) // this will fire when we join a room; track that through the join operation. { roomTracker.TryAddUser(args.RoomName, args.UserData); } }; Client.RoomLeft += (e, args) => { roomTracker.TryRemoveUser(args.RoomName, args.Username); }; Client.Disconnected += async(e, args) => { Console.WriteLine($"Disconnected from Soulseek server: {args.Message}"); // don't reconnect if the disconnecting Exception is either of these types. // if KickedFromServerException, another client was most likely signed in, and retrying will cause a connect loop. // if ObjectDisposedException, the client is shutting down. if (!(args.Exception is KickedFromServerException || args.Exception is ObjectDisposedException)) { Console.WriteLine($"Attepting to reconnect..."); await Client.ConnectAsync(Username, Password); } }; Task.Run(async() => { await Client.ConnectAsync(Username, Password); }).GetAwaiter().GetResult(); Console.WriteLine($"Connected and logged in."); }
/// ----------------------------------------------------------------------------- /// <summary> /// The ReadManifestItem method reads a single node /// </summary> /// <param name="nav">The XPathNavigator representing the node</param> /// <param name="checkFileExists">Flag that determines whether a check should be made</param> /// ----------------------------------------------------------------------------- protected virtual InstallFile ReadManifestItem(XPathNavigator nav, bool checkFileExists) { string fileName = Null.NullString; //Get the path XPathNavigator pathNav = nav.SelectSingleNode("path"); if (pathNav == null) { fileName = DefaultPath; } else { fileName = pathNav.Value + "\\"; } //Get the name XPathNavigator nameNav = nav.SelectSingleNode("name"); if (nameNav != null) { fileName += nameNav.Value; } //Get the sourceFileName string sourceFileName = Util.ReadElement(nav, "sourceFileName"); var file = new InstallFile(fileName, sourceFileName, Package.InstallerInfo); if ((!string.IsNullOrEmpty(BasePath)) && (BasePath.StartsWith("app_code", StringComparison.InvariantCultureIgnoreCase) && file.Type == InstallFileType.Other)) { file.Type = InstallFileType.AppCode; } if (file != null) { //Set the Version string strVersion = XmlUtils.GetNodeValue(nav, "version"); if (!string.IsNullOrEmpty(strVersion)) { file.SetVersion(new Version(strVersion)); } else { file.SetVersion(Package.Version); } //Set the Action string strAction = XmlUtils.GetAttributeValue(nav, "action"); if (!string.IsNullOrEmpty(strAction)) { file.Action = strAction; } if (InstallMode == InstallMode.Install && checkFileExists && file.Action != "UnRegister") { if (File.Exists(file.TempFileName)) { Log.AddInfo(string.Format(Util.FILE_Found, file.Path, file.Name)); } else { Log.AddFailure(Util.FILE_NotFound + " - " + file.TempFileName); } } } return(file); }
public bool IsAdminRequiredForChanges(AutoStartEntry autoStart) { return(BasePath.StartsWith("HKEY_LOCAL_MACHINE")); }