示例#1
0
        /// <summary>
        /// Retrieves the configuration file location for the individual controller.
        /// If using an XInput controller, pass null.
        /// </summary>
        private void GetConfigLocation(DInputController dInputController)
        {
            // Get Configuration Details
            LoaderConfigParser.Config config = LoaderConfigParser.ParseConfig();

            // Set the device type
            ConfigType = config.DirectInputConfigType;

            // If XInput/DInput
            if (DeviceType == InputDeviceType.DirectInput)
            {
                // If InstanceGUID or ProductGUID.
                if (ConfigType == DirectInputConfigType.InstanceGUID)
                {
                    ConfigurationFileLocation = LoaderPaths.GetModLoaderConfigDirectory() + "/Controllers/Instances/" +
                                                dInputController.Information.InstanceGuid + ".json";
                }

                else if (ConfigType == DirectInputConfigType.ProductGUID)
                {
                    ConfigurationFileLocation = LoaderPaths.GetModLoaderConfigDirectory() + "/Controllers/" +
                                                PathSanitizer.ForceValidFilePath(dInputController.Information.ProductName) + ".json";
                }
            }
            else if (DeviceType == InputDeviceType.XInput)
            {
                ConfigurationFileLocation = LoaderPaths.GetModLoaderConfigDirectory() + "/Controllers/XInput/" + "Controller_" + XInputPort + ".json";
            }
        }
示例#2
0
        /* Get resolvers. */

        /// <summary>
        /// Retrieves a summary of all updates to be performed.
        /// </summary>
        public async Task <ModUpdateSummary> GetUpdateDetails()
        {
            if (_resolversWithUpdates == null)
            {
                var resolverManagerPairs = new List <ResolverManagerModResultPair>();
                var resolverTuples       = GetResolvers();
                foreach (var resolverTuple in resolverTuples)
                {
                    var modTuple = resolverTuple.ModTuple;
                    var version  = resolverTuple.Resolver.GetCurrentVersion();

                    // Note: Since R2R Support was added, we cannot predict which DLL will be in use. Just return the config file as main file.
                    string filePath = modTuple.Path;
                    var    metadata = new AssemblyMetadata(PathSanitizer.ForceValidFilePath(modTuple.Object.ModName), version, filePath);

                    var manager      = new UpdateManager(metadata, resolverTuple.Resolver, resolverTuple.Resolver.Extractor);
                    var updateResult = await manager.CheckForUpdatesAsync();

                    if (updateResult.CanUpdate)
                    {
                        resolverManagerPairs.Add(new ResolverManagerModResultPair(resolverTuple.Resolver, manager, updateResult, modTuple));
                    }
                    else
                    {
                        resolverTuple.Resolver.PostUpdateCallback(false);
                    }
                }

                _resolversWithUpdates = resolverManagerPairs;
                return(new ModUpdateSummary(_resolversWithUpdates));
            }

            return(new ModUpdateSummary(_resolversWithUpdates));
        }
示例#3
0
        private bool PerformAction(string action)
        {
            Log.InfoFormat("{0}.PerformAction({1}) called", this, action);
            try
            {
                if (string.IsNullOrEmpty(action))
                {
                    Log.Warn("Warning, action is empty - assume function failed");
                    return(false);
                }

                string cmd  = PathSanitizer.GetExecutable(action);
                string args = PathSanitizer.GetArguments(action);
                Log.InfoFormat("CMD: {0}, ARGS: {1}", cmd, args);

                using (Process p = Process.Start(cmd, args))
                {
                    if (p == null)
                    {
                        Log.Warn("Warning, Process.Start() returned null, assuming function failed");
                        return(false);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Log.Error(string.Format("unable to run action {0}", action), e);
                return(false);
            }
        }
示例#4
0
 public static string ToFolderNameFriendly(this string input)
 {
     if (string.IsNullOrEmpty(input))
     {
         return(null);
     }
     return(Regex.Replace(PathSanitizer.SanitizeFilename(input, ' '), @"\s+", " ").Trim().TrimEnd('.'));
 }
示例#5
0
        public static bool DebugProcessById(int id)
        {
            using (RegistryKey hkKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug", false))
            {
                string debugger = hkKey.GetValue("Debugger") as string;
                if (string.IsNullOrEmpty(debugger))
                {
                    return(false);
                }

                // problem: %ld is not a recognized format sequence in C#, so:

                int k = debugger.IndexOf("%ld");
                if (k >= 0)
                {
                    debugger = debugger.Substring(0, k) + id.ToString() + debugger.Substring(k + 3);
                }
                k = debugger.IndexOf("%ld");
                if (k >= 0)
                {
                    debugger = debugger.Substring(0, k) + "0" + debugger.Substring(k + 3);
                }


                string cmdLine = debugger;

                try
                {
                    ProcessStartInfo startInfo = new ProcessStartInfo(PathSanitizer.GetExecutable(cmdLine));
                    startInfo.WorkingDirectory = Environment.CurrentDirectory;
                    startInfo.Arguments        = PathSanitizer.GetArguments(cmdLine);

                    using (Process p = Process.Start(startInfo))
                    {
                        if (p == null)
                        {
                            Log.Warn("Warning, Process.Start() returned null, assuming function failed");
                            return(false);
                        }
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    Log.Error(string.Format("unable to bring up debugger: {0}", cmdLine), e);
                    return(false);
                }
            }
        }
示例#6
0
        /// <summary>
        /// This program finds an executable on the PATH. It can also find other stuff on the path, but
        /// mostly it finds the executable.s
        /// </summary>
        /// <param name="args"></param>
        private void Run(string[] args)
        {
            Console.OutputEncoding = Encoding.GetEncoding(Encoding.Default.CodePage);

            Args = new InputArgs("which", string.Format(resource.IDS_TITLE, AppVersion.Get()) + "\r\n" + resource.IDS_COPYRIGHT);


            Args.Add(InputArgType.StringList, "extension", null, Presence.Optional, resource.IDS_CMD_extension_doc);
            Args.Add(InputArgType.StringList, "dir", null, Presence.Optional, resource.IDS_CMD_dir_doc);
            Args.Add(InputArgType.Flag, "recursive", false, Presence.Optional, resource.IDS_CMD_recursive_doc);
            Args.Add(InputArgType.Flag, "single", false, Presence.Optional, resource.IDS_CMD_single_doc);
            Args.Add(InputArgType.RemainingParameters, "FILE {FILE}", null, Presence.Required, resource.IDS_CMD_file_doc);
            Args.Add(InputArgType.Parameter, "env", "PATH", Presence.Optional, resource.IDS_CMD_env_doc);

            if (Args.Process(args))
            {
                Filenames   = Args.GetStringList("FILE {FILE}");
                Directories = Args.FindOrCreateStringList("dir");

                string EnvironmentVariableName = Args.GetString("env");
                if (!string.IsNullOrEmpty(EnvironmentVariableName))
                {
                    string env = Environment.GetEnvironmentVariable(EnvironmentVariableName, EnvironmentVariableTarget.User);
                    if (string.IsNullOrEmpty(env))
                    {
                        env = Environment.GetEnvironmentVariable(EnvironmentVariableName);
                    }
                    EnvironmentVariablesAlreadyChecked[EnvironmentVariableName] = true;
                    if (string.IsNullOrEmpty(env))
                    {
                        Console.WriteLine(resource.IDS_ERR_invalid_env_var, EnvironmentVariableName);
                    }
                    else
                    {
                        foreach (string token in env.Split(';'))
                        {
                            Directories.Add(token);
                        }
                    }
                }

                if (FilenamesAreIncludes())
                {
                    AddEnvBasedDirectories("INCLUDE");
                }
                else if (FilenamesAreLibs())
                {
                    AddEnvBasedDirectories("LIB");
                }
                else
                {
                    // default: use standard windows lookup
                    Directories.Add(Directory.GetCurrentDirectory());
                    Directories.Add(PathSanitizer.GetWindowsDirectory());
                    Directories.Add(PathSanitizer.Get32BitSystemDirectory());
                    Directories.Add(Environment.SystemDirectory);
                    Directories.Add(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName));
                    Directories.Add(Environment.GetFolderPath(Environment.SpecialFolder.System));
                    Directories.Add(Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.System)));
                    AddEnvBasedDirectories("PATH");
                }

                Directories.MakeUnique(StringComparison.OrdinalIgnoreCase);

                List <string> Extensions = Args.FindOrCreateStringList("extension");
                if (Extensions.Count == 0)
                {
                    foreach (string path in Environment.GetEnvironmentVariable("PATHEXT").Split(';'))
                    {
                        Extensions.Add(path);
                    }
                }

                List <string> FoundItems = new List <string>();
                foreach (string filename in Filenames)
                {
                    bool found = false;
                    foreach (string foundname in Locate(filename))
                    {
                        if (!Contains(FoundItems, foundname))
                        {
                            FileInfo fi = new FileInfo(foundname);

                            Console.WriteLine(resource.IDS_RESULT_PATTERN,
                                              foundname, fi.LastWriteTime, fi.Length);
                            FoundItems.Add(foundname);
                            if (Args.GetFlag("single"))
                            {
                                break;
                            }

                            found = true;
                        }
                    }
                    if (!found)
                    {
                        Console.WriteLine(resource.IDS_ERR_not_found, filename);
                    }
                }
            }
        }
示例#7
0
 private string GetFullPath(string systemName) => Path.Combine(_path, PathSanitizer.SanitizePath(systemName));