static void DirSearch(string dir, StartupDataHandlerResult result) { string basePath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Web"; try { foreach (string f in Directory.GetFiles(dir)) { string widgetJS = File.ReadAllText(f); string widgetName = ParseVariable(widgetJS, "_name"); string widgetIcon = ParseVariable(widgetJS, "_icon"); string widgetDescription = ParseVariable(widgetJS, "_description"); string widgetTab = ParseVariable(widgetJS, "_tab"); string className = GetClassName(widgetJS); string widgetPath = f.Replace(basePath, ""); widgetPath = widgetPath.Replace("\\", "/"); StartupDataWidgetInfo widget = new StartupDataWidgetInfo() { Name = widgetName, Icon = widgetIcon, Description = widgetDescription, Path = widgetPath, Tab = widgetTab, ClassName = className }; result.Widgets.Add(widget); } foreach (string d in Directory.GetDirectories(dir)) { DirSearch(d, result); } } catch (System.Exception ex) { Console.WriteLine(ex.Message); } }
public static StartupDataHandlerResult ProcessStartupRequest(TelemetryData telemetry, Dictionary <string, IGame> plugins, NameValueCollection postData) { StartupDataHandlerResult result = new StartupDataHandlerResult() { Result = false }; result.Plugins = new List <StarupDataHandlerPlugin>(); result.Pages = new List <StartupDataPageInfo>(); result.Widgets = new List <StartupDataWidgetInfo>(); result.DefaultPage = "Home"; result.Version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion; foreach (var key in plugins) { IGame game = key.Value; StarupDataHandlerPlugin plugin = new StarupDataHandlerPlugin(); plugin.PluginName = ""; plugin.GameShortName = game.Name; plugin.GameLongName = game.DisplayName; plugin.PluginVersion = game.Version; plugin.Author = game.Author; plugin.URL = game.URL; plugin.Supports = (int)game.Supports; result.Plugins.Add(plugin); } string basePath = Directory.GetCurrentDirectory(); basePath += @"\Web\js\pages"; string[] pageJsonFiles = Directory.GetFiles(basePath, "*.js"); for (int i = 0; i < pageJsonFiles.Length; i++) { string pageText = File.ReadAllText(pageJsonFiles[i]); string pageName = ParseVariable(pageText, "_name"); string pageIcon = ParseVariable(pageText, "_icon"); string menuIcon = ParseVariable(pageText, "_menuIcon"); string pageDescription = ParseVariable(pageText, "_description"); string order = ParseVariable(pageText, "_order", false); int pageOrder = 1; if (!int.TryParse(order, out pageOrder)) { pageOrder = 1; } if (pageName != null && pageIcon != null && pageDescription != null) { StartupDataPageInfo pageInfo = new StartupDataPageInfo(); pageInfo.Name = pageName; pageInfo.Icon = pageIcon; pageInfo.Menuicon = menuIcon; pageInfo.Description = pageDescription; pageInfo.Order = pageOrder; pageInfo.FileName = "js/pages/" + Path.GetFileName(pageJsonFiles[i]); result.Pages.Add(pageInfo); } } result.Pages = result.Pages.OrderBy(o => o.Order).ToList(); basePath = Directory.GetCurrentDirectory(); basePath += @"\Web\js\widgets"; DirSearch(basePath, result); return(result); }