/*public LocationsModel() * { * _searchPathList = new List<SearchPath>(); * _locationsObservable = new ObservableCollection<SearchPathViewModel>(); * }*/ public LocationsModel(CoreLib core, List <Location> list) { _core = core; _searchLocationsObservable = new ObservableCollection <SearchPathViewModel>(); foreach (var path in list) { SearchPathViewModel spvm = new SearchPathViewModel(path); _searchLocationsObservable.Add(spvm); } }
/// <summary> /// Loads a package stream for the CustomResources file for the specified game /// </summary> /// <param name="game"></param> /// <returns></returns> public static MemoryStream GetCustomAppResourceStream(MEGame game) { var zStream = LoadEmbeddedFile("GameResources.zip"); if (zStream != null) { return(LoadFileFromZipStream(zStream, CoreLib.CustomResourceFileName(game))); } return(null); }
public override void BringToFront() { CoreLib.Log("BringToFront"); //Interop.BringWindowToTop(hwnd); Interop.ShowWindow(hwnd, Interop.SW_SHOW); if (Interop.IsIconic(hwnd)) { Interop.ShowWindow(hwnd, Interop.SW_RESTORE); } Interop.SetForegroundWindow(hwnd); }
public SearchDllCommand(MainViewModel mainViewModel, CoreLib core, IWindowService windowService) { this._mainViewModel = mainViewModel; this._core = core; this._windowService = windowService; // установка таймера _timer = new DispatcherTimer(); _timer.Tick += OnTimerTick; _timer.Interval = new TimeSpan(0, 0, 1); }
public static LocationsModel Load(CoreLib core) { List <Location> list = SerializeHelper <List <Location> > .Load(_fileName); if (list == null) { list = new List <Location>(); } LocationsModel model = new LocationsModel(core, list); return(model); }
public static void Init() { if (initialized) { return; } var sc = new SynchronizationContext(); SynchronizationContext.SetSynchronizationContext(sc); CoreLib.InitLib(TaskScheduler.FromCurrentSynchronizationContext(), x => { }); #if AZURE ME1Directory.DefaultGamePath = ME1UnrealObjectInfo.MiniGameFilesPath = GetTestMiniGamePath(MEGame.ME1); ME2Directory.DefaultGamePath = ME2UnrealObjectInfo.MiniGameFilesPath = GetTestMiniGamePath(MEGame.ME2); ME3Directory.DefaultGamePath = ME3UnrealObjectInfo.MiniGameFilesPath = GetTestMiniGamePath(MEGame.ME3); #endif initialized = true; }
public ClockPlugin(TPanel panel, PluginConfig cfg) : base(panel, cfg) { button = new ToggleButton(); button.Add(new Label("DateTime")); /* button.Clicked += (s, e) => { * if (button.Active) * Open(); * else * Close(); * };*/ button.Clicked += (s, e) => { CoreLib.Signal("test"); }; }
public static void Main(string[] args) { Application.Init(); //var dwin = new DesktopWindow(); //dwin.Show(); /*GLib.ExceptionManager.UnhandledException += (e) => { * e.ExitApplication = false; * CoreLib.Log(e.ExceptionObject.ToString()); * };*/ try { var logwin = new LogWindow(); logwin.Show(); CoreLib.Log("log started"); AppConfig.Load("../config/config.xml"); //Gtk.Settings.Default.ThemeName = "Dorian-3.16"; var shellMan = ShellManager.Create(); shellMan.UpdateWindows(); var idx = new TLauncherIndex(); idx.AddLocations(); idx.Rebuild(); foreach (var panConfig in AppConfig.Panels) { var pwin = new TPanel(panConfig); pwin.Setup(); pwin.Show(); } } catch (Exception ex) { CoreLib.MessageBox(ex.ToString()); } Application.Run(); }
public MainViewModel() { _core = new CoreLib(); _windowService = new WindowService(); //LocationsModel = new LocationsModel(_core); LocationsModel = LocationsModel.Load(_core); Options = new Option(_core); _ignoreStorage = IgnoreStorage.Load(); _configuration = TinyIoCContainer.Current.Resolve <IConfigurationModel>(); _configuration.PropertyChanged += OnConfigurationPropertyChanged; UndoRedoEngine undoRedoEngine = new UndoRedoEngine(_configuration); _undoRedoEngine = undoRedoEngine; _undoRedoEngine.PropertyChanged += OnUndoRedoEnginePropertyChanged; TinyIoCContainer.Current.Register <IUndoRedoEngine, UndoRedoEngine>(undoRedoEngine); ThumbnailProvider.Instance.PropertyChanged += OnThumbnailProviderPropertyChanged; }
private void createButton(TWindow wnd) { CoreLib.Log(wnd.hwnd.ToString()); var but = new TWindowButton(wnd); var img = wnd.GetIcon(new Size(22, 22)); if (img != null) { but.Image = img; img.Show(); } but.Label = wnd.GetName(); buttonTable.Add(but); buthash2.Add(wnd, but); //but.Clicked += (s, e) => { //wnd.BringToFront(); //}; }
public WindowListPlugin(TPanel panel, PluginConfig cfg) : base(panel, cfg) { buttonTable = new PanelButtonTable(Orientation.Horizontal); //box.HeightRequest = panel.height; Update(); ShellManager.Current.WindowActivated += (wnd) => { var bt = GetButton(wnd); if (bt != null) { CoreLib.Log("act"); Application.Invoke((s, e) => { foreach (var b in buthash2.Values) { b.Active = bt == b; } }); //bt.Toggle(); } }; ShellManager.Current.WindowDestroyed += (wnd) => { var bt = GetButton(wnd); if (bt != null) { buthash2.Remove(wnd); buttonTable.Remove(bt); bt.Dispose(); } }; ShellManager.Current.WindowCreated += (wnd) => { if (wnd.ShowInTaskbar()) { createButton(wnd); } }; }
public static void ResolveShortcut(string filename, out string name, out string command, out string args, out string description, out string iconLocation, out int iconIndex) { ShellLink link = new ShellLink(); ((IPersistFile)link).Load(filename, STGM_READ); // TODO: if I can get hold of the hwnd call resolve first. This handles moved and renamed files. //((IShellLinkW)link).Resolve(IntPtr.Zero, SLR_FLAGS.SLR_ANY_MATCH); StringBuilder sb = new StringBuilder(MAX_PATH); WIN32_FIND_DATAW data = new WIN32_FIND_DATAW(); ((IShellLinkW)link).GetPath(sb, sb.Capacity, out data, SLGP_FLAGS.SLGP_RAWPATH); command = sb.ToString(); sb = new StringBuilder(MAX_PATH); //MAX_PATH? ((IShellLinkW)link).GetArguments(sb, sb.Capacity); args = sb.ToString(); description = ""; try { sb = new StringBuilder(MAX_PATH); //MAX_PATH? ((IShellLinkW)link).GetDescription(sb, sb.Capacity); description = sb.ToString(); } catch (COMException ex) { } sb = new StringBuilder(MAX_PATH); //MAX_PATH? var hresult = ((IShellLinkW)link).GetIconLocation(sb, sb.Capacity, out iconIndex); iconLocation = sb.ToString(); if (hresult != 0) { CoreLib.Log("GetIconLocation result: " + hresult); } name = GetLocalizedName.GetName(filename); }
private static void initCoreLib() { #if DEBUG MemoryAnalyzer.IsTrackingMemory = true; #endif void packageSaveFailed(string message) { // I'm not sure if this requires ui thread since it's win32 but i'll just make sure Application.Current.Dispatcher.Invoke(() => { MessageBox.Show(message); }); } CoreLib.InitLib(TaskScheduler.FromCurrentSynchronizationContext(), packageSaveFailed); CoreLibSettingsBridge.MapSettingsIntoBridge(); PackageSaver.CheckME3Running = () => { GameController.TryGetME3Process(out var me3Proc); return(me3Proc != null); }; PackageSaver.NotifyRunningTOCUpdateRequired = GameController.SendTOCUpdateMessage; PackageSaver.GetPNGForThumbnail = texture2D => texture2D.GetPNG(texture2D.GetTopMip()); }
internal static void Initialize() { if (Initialized) { return; } Initialized = true; try { CoreLogger = new GadgetLogger("GadgetCore", "Core"); CoreLogger.Log("GadgetCore v" + GadgetCoreAPI.FULL_VERSION + " Initializing!"); Debug.Log("GadgetCore v" + GadgetCoreAPI.FULL_VERSION); } catch (Exception e) { Debug.Log(e); GadgetCoreAPI.Quit(); return; } try { if (File.Exists(Application.persistentDataPath + "/PlayerPrefs.txt") && VerifySaveFile()) { if (GadgetCoreConfig.MaxBackups > 0) { File.Copy(Application.persistentDataPath + "/PlayerPrefs.txt", Path.Combine(GadgetPaths.SaveBackupsPath, "Save Backup - " + DateTime.Now.ToString("yyyy-dd-M_HH-mm-ss") + ".txt")); FileInfo[] backups = new DirectoryInfo(GadgetPaths.SaveBackupsPath).GetFiles().OrderByDescending(x => x.LastWriteTime.Year <= 1601 ? x.CreationTime : x.LastWriteTime).ToArray(); if (backups.Length > GadgetCoreConfig.MaxBackups) { for (int i = GadgetCoreConfig.MaxBackups; i < backups.Length; i++) { backups[i].Delete(); } } } } else { GadgetCoreAPI.Quit(); return; } HarmonyInstance = new Harmony("GadgetCore.core"); Type[] types; try { types = Assembly.GetExecutingAssembly().GetTypes(); } catch (ReflectionTypeLoadException e) { types = e.Types.Where(t => t != null).ToArray(); } types.Do(delegate(Type type) { object[] attributes = type.GetCustomAttributes(true); if (!attributes.Any(x => x.GetType() == typeof(HarmonyGadgetAttribute))) { HarmonyInstance.CreateClassProcessor(type).Patch(); } }); new Thread(new ThreadStart(() => { Thread.CurrentThread.Name = "GadgetCore Unity Engine Log Cloner"; Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Lowest; Thread.CurrentThread.IsBackground = true; string logPath = Application.dataPath + "\\output_log.txt"; if (!File.Exists(logPath)) { logPath = Application.persistentDataPath + "\\output_log.txt"; } if (!File.Exists(logPath)) { logPath = "~/Library/Logs/Unity/Player.log"; } if (!File.Exists(logPath)) { logPath = "~/.config/unity3d/DefaultCompany/Roguelands/Player.log"; } if (!File.Exists(logPath)) { CoreLogger.LogWarning("Unable to find Unity log file!"); return; } string targetPath = Path.Combine(GadgetPaths.LogsPath, "Unity Output.log"); DateTime t = default; while (!Quitting) { if (File.Exists(logPath) && File.GetLastWriteTime(logPath) > t) { File.Copy(logPath, targetPath, true); t = DateTime.Now; } Thread.Sleep(100); } })).Start(); AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) => { string name = new AssemblyName(args.Name).Name; if (LoadedAssemblies.ContainsKey(name)) { return(LoadedAssemblies[name]); } foreach (string file in Directory.GetFiles(GadgetPaths.LibsPath)) { if (AssemblyName.GetAssemblyName(file).Name == name) { Assembly assembly = Assembly.LoadFrom(file); LoadedAssemblies[name] = assembly; return(assembly); } } return(null); }; AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (object sender, ResolveEventArgs args) => { string name = new AssemblyName(args.Name).Name; if (LoadedAssemblies.ContainsKey("ReflectionOnly: " + name)) { return(LoadedAssemblies["ReflectionOnly: " + name]); } foreach (string file in Directory.GetFiles(GadgetPaths.LibsPath)) { if (AssemblyName.GetAssemblyName(file).Name == name) { Assembly assembly = Assembly.ReflectionOnlyLoadFrom(file); LoadedAssemblies["ReflectionOnly: " + name] = assembly; return(assembly); } } return(null); }; LoadMainMenu(); try { UMFAPI = new UMFAPI(); UMFAPI.GetModNames(); CoreLogger.Log("Enabling UMF API as UMF is installed."); } catch (Exception) { UMFAPI = null; CoreLogger.Log("Disabling UMF API as UMF is not installed."); } CoreLib = Activator.CreateInstance(Assembly.LoadFile(Path.Combine(Path.Combine(GadgetPaths.GadgetCorePath, "DependentLibs"), "GadgetCoreLib.dll")).GetTypes().First(x => typeof(IGadgetCoreLib).IsAssignableFrom(x))) as IGadgetCoreLib; CoreLib.ProvideLogger(CoreLogger); GadgetCoreConfig.Load(); CoreLogger.Log("Finished loading config."); RegisterKeys(); IniData coreManifest = new IniData(); coreManifest["Metadata"]["Name"] = "GadgetCore"; coreManifest["Metadata"]["Assembly"] = Path.Combine(GadgetPaths.ManagedPath, "GadgetCore.dll"); GadgetMod coreMod = new GadgetMod(GadgetPaths.GadgetCorePath, coreManifest, Assembly.GetExecutingAssembly()); GadgetMods.RegisterMod(coreMod); VanillaRegistration(); SceneManager.sceneLoaded += OnSceneLoaded; SceneInjector.InjectMainMenu(); GadgetLoader.LoadAllMods(); DontDestroyOnLoad(new GameObject("GadgetCore", typeof(GadgetCore))); CoreLogger.LogConsole("GadgetCore v" + GadgetCoreAPI.FULL_VERSION + " Initialized!"); #pragma warning disable CS0162 // Unreachable code detected if (GadgetCoreAPI.IS_BETA) { CoreLogger.LogWarning("You are currently running a beta version of GadgetCore! Be prepared for bugs!"); } #pragma warning restore CS0162 // Unreachable code detected } catch (Exception e) { CoreLogger.LogError("There was a fatal error loading GadgetCore: " + e); } }
public string Generate(bool indent) { var i = indent ? " " : ""; var sb = new StringBuilder(); sb.Append($"{i}nuget_package(\n"); if (Variable == null) { sb.Append($"{i} name = \"{PackageIdentity.Id.ToLower()}\",\n"); } else { sb.Append($"{i} name = {Variable},\n"); } sb.Append($"{i} package = \"{PackageIdentity.Id.ToLower()}\",\n"); sb.Append($"{i} version = \"{PackageIdentity.Version}\",\n"); if (!String.IsNullOrEmpty(Sha256)) { sb.Append($"{i} sha256 = \"{Sha256}\",\n"); } if (NugetSourceCustom) { sb.Append($"{i} source = source,\n"); } if (CoreLib != null && CoreLib.Any()) { sb.Append($"{i} core_lib = {{\n"); foreach (var pair in CoreLib) { sb.Append($"{i} \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append($"{i} }},\n"); } if (CoreRef != null && CoreRef.Any()) { sb.Append($"{i} core_ref = {{\n"); foreach (var pair in CoreRef) { sb.Append($"{i} \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append($"{i} }},\n"); } if (NetLib != null && NetLib.Any()) { sb.Append($"{i} net_lib = {{\n"); foreach (var pair in NetLib) { sb.Append($"{i} \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append($"{i} }},\n"); } if (NetRef != null && NetRef.Any()) { sb.Append($"{i} net_ref = {{\n"); foreach (var pair in NetRef) { sb.Append($"{i} \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append($"{i} }},\n"); } if (!String.IsNullOrEmpty(MonoLib)) { sb.Append($"{i} mono_lib = \"{MonoLib}\",\n"); } if (!String.IsNullOrEmpty(MonoRef)) { sb.Append($"{i} mono_ref = \"{MonoRef}\",\n"); } if (CoreTool != null && CoreTool.Sum(x => x.Value.Count()) > 0) { sb.Append($"{i} core_tool = {{\n"); foreach (var pair in CoreTool) { sb.Append($"{i} \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append($"{i} }},\n"); } if (NetTool != null && NetTool.Sum(x => x.Value.Count()) > 0) { sb.Append($"{i} net_tool = {{\n"); foreach (var pair in NetTool) { sb.Append($"{i} \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append($"{i} }},\n"); } if (!String.IsNullOrEmpty(MonoTool)) { sb.Append($"{i} mono_tool = \"{MonoTool}\",\n"); } if (Core_Deps != null && Core_Deps.Sum(x => x.Value.Count()) > 0) { sb.Append($"{i} core_deps = {{\n"); foreach (var pair in Core_Deps) { if (!pair.Value.Any()) { continue; } sb.Append($"{i} \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($"{i} \"{s}\",\n"); } sb.Append($"{i} ],\n"); } sb.Append($"{i} }},\n"); } if (Net_Deps != null && Net_Deps.Sum(x => x.Value.Count()) > 0) { sb.Append($"{i} net_deps = {{\n"); foreach (var pair in Net_Deps) { if (!pair.Value.Any()) { continue; } sb.Append($"{i} \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($"{i} \"{s}\",\n"); } sb.Append($"{i} ],\n"); } sb.Append($"{i} }},\n"); } if (Mono_Deps != null && Mono_Deps.Any()) { sb.Append($"{i} mono_deps = [\n"); foreach (var s in Mono_Deps) { sb.Append($"{i} \"{s}\",\n"); } sb.Append($"{i} ],\n"); } if (Core_Files != null && Core_Files.Sum(x => x.Value.Count()) > 0) { sb.Append($"{i} core_files = {{\n"); foreach (var pair in Core_Files) { if (!pair.Value.Any()) { continue; } sb.Append($"{i} \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($"{i} \"{s}\",\n"); } sb.Append($"{i} ],\n"); } sb.Append($"{i} }},\n"); } if (Net_Files != null && Net_Files.Sum(x => x.Value.Count()) > 0) { sb.Append($"{i} net_files = {{\n"); foreach (var pair in Net_Files) { if (!pair.Value.Any()) { continue; } sb.Append($"{i} \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($"{i} \"{s}\",\n"); } sb.Append($"{i} ],\n"); } sb.Append($"{i} }},\n"); } if (Mono_Files != null && Mono_Files.Any()) { sb.Append($"{i} mono_files = [\n"); foreach (var s in Mono_Files) { sb.Append($"{i} \"{s}\",\n"); } sb.Append($"{i} ],\n"); } sb.Append($"{i})\n"); return(sb.ToString()); }
public ConfigurationViewModel(IConfigurationModel configuration, IWindowService windowService, CoreLib core, Option option) { this._configuration = configuration; _windowService = windowService; _core = core; Delay = 500; _thumbnailWidth = _configuration.ThumbnailWidth; Option = option; }
public string Generate() { var sb = new StringBuilder(); sb.Append($"nuget_package(\n"); sb.Append($" name = \"{PackageIdentity.Id.ToLower()}\",\n"); sb.Append($" package = \"{PackageIdentity.Id.ToLower()}\",\n"); sb.Append($" version = \"{PackageIdentity.Version}\",\n"); if (!String.IsNullOrEmpty(Sha256)) { sb.Append($" sha256 = \"{Sha256}\",\n"); } if (CoreLib != null && CoreLib.Any()) { sb.Append(" core_lib = {\n"); foreach (var pair in CoreLib) { sb.Append($" \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append(" },\n"); } if (NetLib != null && NetLib.Any()) { sb.Append(" net_lib = {\n"); foreach (var pair in NetLib) { sb.Append($" \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append(" },\n"); } if (!String.IsNullOrEmpty(MonoLib)) { sb.Append($" mono_lib = \"{MonoLib}\",\n"); } if (CoreTool != null && CoreTool.Sum(x => x.Value.Count()) > 0) { sb.Append(" core_tool = {\n"); foreach (var pair in NetTool) { sb.Append($" \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append(" },\n"); } if (NetTool != null && NetTool.Sum(x => x.Value.Count()) > 0) { sb.Append(" net_tool = {\n"); foreach (var pair in NetTool) { sb.Append($" \"{pair.Key}\": \"{pair.Value}\",\n"); } sb.Append(" },\n"); } if (!String.IsNullOrEmpty(MonoTool)) { sb.Append($" mono_tool = \"{MonoTool}\",\n"); } if (Core_Deps != null && Core_Deps.Sum(x => x.Value.Count()) > 0) { sb.Append(" core_deps = {\n"); foreach (var pair in Net_Deps) { if (!pair.Value.Any()) { continue; } sb.Append($" \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($" \"{s}\",\n"); } sb.Append(" ],\n"); } sb.Append(" },\n"); } if (Net_Deps != null && Net_Deps.Sum(x => x.Value.Count()) > 0) { sb.Append(" net_deps = {\n"); foreach (var pair in Net_Deps) { if (!pair.Value.Any()) { continue; } sb.Append($" \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($" \"{s}\",\n"); } sb.Append(" ],\n"); } sb.Append(" },\n"); } if (Mono_Deps != null && Mono_Deps.Any()) { sb.Append($" mono_deps = [\n"); foreach (var s in Mono_Deps) { sb.Append($" \"{s}\",\n"); } sb.Append($" ],\n"); } if (Core_Files != null && Core_Files.Sum(x => x.Value.Count()) > 0) { sb.Append(" core_files = {\n"); foreach (var pair in Core_Files) { if (!pair.Value.Any()) { continue; } sb.Append($" \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($" \"{s}\",\n"); } sb.Append(" ],\n"); } sb.Append(" },\n"); } if (Net_Files != null && Net_Files.Sum(x => x.Value.Count()) > 0) { sb.Append(" net_files = {\n"); foreach (var pair in Net_Files) { if (!pair.Value.Any()) { continue; } sb.Append($" \"{pair.Key}\": [\n"); foreach (var s in pair.Value) { sb.Append($" \"{s}\",\n"); } sb.Append(" ],\n"); } sb.Append(" },\n"); } if (Mono_Files != null && Mono_Files.Any()) { sb.Append($" mono_files = [\n"); foreach (var s in Mono_Files) { sb.Append($" \"{s}\",\n"); } sb.Append($" ],\n"); } sb.Append($")\n"); return(sb.ToString()); }
public void Log() { CoreLib.Log("HWND: " + hwnd.ToString() + ", Name: " + GetName()); }
public static void Main(string[] arg) { // *** Parse arguments. if (arg.Length == 0) { PrintUsage(); return; } bool optRunTests = false; bool optInteractiveMode = false; bool optVerbose = false; bool optPause = false; bool optDump = false; List <string> optFiles = new List <string>(); List <string> passThroughArgs = null; for (int iArg = 0; iArg < arg.Length; ++iArg) { string ar = arg[iArg]; if (ar[0] == '-' || ar[0] == '/') { if (ar[1] == 't') { optRunTests = true; } else if (ar[1] == 'i') { optInteractiveMode = true; } else if (ar[1] == 'v') { Console.WriteLine("verbose enabled."); optVerbose = true; } else if (ar[1] == 'p') { optPause = true; } else if (ar[1] == 'd') { optDump = true; } else if (ar[1] == 'a') { if (iArg == arg.Length - 1) { Console.WriteLine("Argument expected after -a option."); PrintUsage(); return; } else { passThroughArgs = passThroughArgs ?? new List <string>(); passThroughArgs.Add(arg[++iArg]); } } else { Console.WriteLine("Unrecognized option '" + ar[1] + "'."); PrintUsage(); return; } } else { optFiles.Add(ar); } } // *** Initialize engine. // Create engine. Engine engine = new Engine(); engine.LogError = (msg) => { ConsoleColor sav = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(msg); Console.ForegroundColor = sav; }; // Register optional libraries. DebugLib.Register(engine); FileLib.Register(engine); DateTimeLib.Register(engine); ConsoleLib.Register(engine); List <ParseErrorInst> errors = new List <ParseErrorInst>(); // Create pass-through args. if (null != passThroughArgs) { string initScript = "global List<string> CLIargs = new { "; foreach (string pta in passThroughArgs) { initScript += "Add(\"" + pta + "\"); "; } initScript += "};"; ScriptResult result = engine.RunScript(initScript, false); if (!result.success) { Console.WriteLine("INTERNAL ERROR creating passthrough arguments array."); return; } errors.Clear(); } // *** Do tasks. // Tests... if (optRunTests) { UnitTests.RunTests(engine, optVerbose); } // Files... foreach (string filename in optFiles) { string fileContents; try { fileContents = File.ReadAllText(filename); } catch (Exception e) { Console.WriteLine("Error attempting to open '" + filename + "': " + e.Message); break; } errors.Clear(); ScriptResult result = engine.RunScript(fileContents, optVerbose, filename); if (result.success) { Console.WriteLine("Returned: " + CoreLib.ValueToString(engine.defaultContext, result.value, true)); } else { // At time of writing, errors get printed (in red) when they are created, so don't need to do it again here. //Console.WriteLine(result); Console.WriteLine(" " + filename + " failed to compile or execute."); } } // Interactive mode... if (optInteractiveMode) { Console.WriteLine("Pebble Interpreter (C) 2021 Patrick Cyr"); Console.WriteLine("Interactive mode. Enter 'exit' to exit, 'help' for help:"); // Lines in interactive mode don't use their own scope. Instead, they // use one shared scope that is created here. engine.defaultContext.stack.PushTerminalScope("<interactive mode>", null); while (true) { Console.Write("> "); string line = Console.ReadLine(); line = line.Trim(); if (line.Equals("exit", StringComparison.OrdinalIgnoreCase)) { break; } if (line.Equals("help", StringComparison.OrdinalIgnoreCase)) { line = "Debug::DumpClass(\"Debug\");"; Console.WriteLine(line); } ScriptResult result = engine.RunInteractiveScript(line, optVerbose); if (result.success) { if (null == result.value) { Console.WriteLine("<null>"); } else { Console.WriteLine(CoreLib.ValueToString(engine.defaultContext, result.value, true)); } } } } // Dump memory... if (optDump) { Console.WriteLine(); Console.WriteLine(engine.defaultContext); } // Pause before exiting... if (optPause) { Console.WriteLine("Press any key to exit."); Console.ReadKey(); } }
public MainViewModel() { _coreLib = new CoreLib(); }
public static PropertyCollection getDefaultStructValue(string className, bool stripTransients) { bool isImmutable = UnrealObjectInfo.IsImmutable(className, MEGame.ME2); if (Structs.ContainsKey(className)) { ClassInfo info = Structs[className]; try { PropertyCollection structProps = new PropertyCollection(); ClassInfo tempInfo = info; while (tempInfo != null) { foreach ((string propName, PropertyInfo propInfo) in tempInfo.properties) { if (stripTransients && propInfo.Transient) { continue; } if (getDefaultProperty(propName, propInfo, stripTransients, isImmutable) is Property uProp) { structProps.Add(uProp); } } if (!Structs.TryGetValue(tempInfo.baseClass, out tempInfo)) { tempInfo = null; } } structProps.Add(new NoneProperty()); string filepath = null; if (ME2Directory.BioGamePath != null) { filepath = Path.Combine(ME2Directory.BioGamePath, info.pccPath); } Stream loadStream = null; if (File.Exists(info.pccPath)) { filepath = info.pccPath; loadStream = new MemoryStream(File.ReadAllBytes(info.pccPath)); } else if (info.pccPath == UnrealObjectInfo.Me3ExplorerCustomNativeAdditionsName) { filepath = "GAMERESOURCES_ME2"; loadStream = Utilities.LoadFileFromCompressedResource("GameResources.zip", CoreLib.CustomResourceFileName(MEGame.ME2)); } else if (filepath != null && File.Exists(filepath)) { loadStream = new MemoryStream(File.ReadAllBytes(filepath)); } #if AZURE else if (MiniGameFilesPath != null && File.Exists(Path.Combine(MiniGameFilesPath, info.pccPath))) { // Load from test minigame folder. This is only really useful on azure where we don't have access to // games filepath = Path.Combine(MiniGameFilesPath, info.pccPath); loadStream = new MemoryStream(File.ReadAllBytes(filepath)); } #endif if (loadStream != null) { using (IMEPackage importPCC = MEPackageHandler.OpenMEPackageFromStream(loadStream, filepath, useSharedPackageCache: true)) { var exportToRead = importPCC.GetUExport(info.exportIndex); byte[] buff = exportToRead.Data.Skip(0x30).ToArray(); PropertyCollection defaults = PropertyCollection.ReadProps(exportToRead, new MemoryStream(buff), className); foreach (var prop in defaults) { structProps.TryReplaceProp(prop); } } } return(structProps); } catch { return(null); } } return(null); }
/// <summary> /// Writes data stored in memory to an appriopriate text format. /// </summary> /// <param name="fileName"></param> public void DumpToFile(string fileName) { File.Delete(fileName); /* for now, it's better not to sort, to preserve original order */ // StringRefs.Sort(CompareTlkStringRef); int totalCount = StringRefs.Count(); int count = 0; int lastProgress = -1; XmlTextWriter xr = new XmlTextWriter(fileName, Encoding.UTF8); xr.Formatting = Formatting.Indented; xr.Indentation = 4; xr.WriteStartDocument(); xr.WriteStartElement("tlkFile"); xr.WriteAttributeString("TLKToolVersion", CoreLib.GetVersion()); xr.WriteComment("Male entries section begin"); foreach (var s in StringRefs) { if (s.Index == Header.MaleEntryCount) { xr.WriteComment("Male entries section end"); xr.WriteComment("Female entries section begin"); } xr.WriteStartElement("String"); xr.WriteStartAttribute("id"); xr.WriteValue(s.StringID); xr.WriteEndAttribute(); if (s.BitOffset < 0) { xr.WriteStartAttribute("calculatedID"); xr.WriteValue(-(Int32.MinValue - s.StringID)); xr.WriteEndAttribute(); xr.WriteString("-1"); } else { xr.WriteString(s.Data); } xr.WriteEndElement(); // </string> int progress = (++count * 100) / totalCount; if (progress > lastProgress) { lastProgress = progress; OnProgressChanged(lastProgress); } } xr.WriteComment("Female entries section end"); xr.WriteEndElement(); // </tlkFile> xr.Flush(); xr.Close(); }
public static TLauncherEntry CreateFromFileLnk(string path) { var entry = new TLauncherEntry(); string name, command, args, description, iconLocation; int iconIndex; ResolveShortcut(path, out name, out command, out args, out description, out iconLocation, out iconIndex); command = Environment.ExpandEnvironmentVariables(command); if (!File.Exists(command)) { var newCommand = command.Replace("\\Program Files (x86)", "\\Program Files").Replace("\\system32", "\\Sysnative"); if (File.Exists(newCommand)) { command = newCommand; } else { CoreLib.Log("COMMAND NOT FOUND: '" + command + "'"); } } if (string.IsNullOrEmpty(iconLocation)) { iconLocation = command; iconIndex = 0; } //if (name == "Steam") { // AppLib.log("########################################################" + iconLocation); //} iconLocation = Environment.ExpandEnvironmentVariables(iconLocation); if (!File.Exists(iconLocation)) { //AppLib.log("COMMAND NOT FOUND: " + command); iconLocation = iconLocation.Replace("\\Program Files (x86)", "\\Program Files").Replace("\\system32", "\\Sysnative"); } if (File.Exists(iconLocation)) { //var ext = new TsudaKageyu.IconExtractor(iconLocation); //var ico = ext.GetIcon(iconIndex); IntPtr p1 = new IntPtr(); IntPtr p2 = new IntPtr(); Interop.ExtractIconEx(iconLocation, iconIndex, ref p1, ref p2, 1); System.Drawing.Icon ico; if (p1 != IntPtr.Zero) { ico = System.Drawing.Icon.FromHandle(p1); } else { ico = System.Drawing.Icon.FromHandle(p2); } var ms = new MemoryStream(); ico.ToBitmap().Save(ms, System.Drawing.Imaging.ImageFormat.Png); entry.IconStored = ms.ToArray(); } else { CoreLib.Log("ICON LOCATION NOT FOUND: " + iconLocation); } if (path.Contains("ANNO")) { var s = ""; } entry.Name = name; entry.CommandPath = Path.GetDirectoryName(command); entry.CommandFile = Path.GetFileName(command); entry.CommandArgs = args; entry.Description = description; SetCategory(entry); return(entry); }