Example #1
0
        /// <summary>
        /// Kills the first ExeModules on the OS that matches the string.
        /// </summary>
        /// <returns><c>true</c>, if ExeModule was killed, <c>false</c> otherwise.</returns>
        /// <param name="os">The OS.</param>
        /// <param name="input">The input string (or string representation of the integer PID) to search against.</param>
        /// <param name="searchName">If set to <c>true</c> then can search by IdentifierName.</param>
        /// <param name="shouldWrite">If set to <c>true</c> will write success and failure to the OS.</param>
        public static bool KillExecutableModule(this Hacknet.OS os, string input, bool searchName = false, bool shouldWrite = false)
        {
            int i;

            Hacknet.ExeModule mod = null;
            input = input.Trim();
            if (int.TryParse(input, out i))
            {
                mod = os.exes.Find((obj) => obj.PID == i);
                if (mod == null && shouldWrite)
                {
                    os.WriteLine(Locale.Get("Invalid PID"));
                }
            }
            else if (searchName && !string.IsNullOrWhiteSpace(input))
            {
                mod = os.exes.Find((obj) => obj.IdentifierName == input);
                if (mod == null && shouldWrite)
                {
                    os.WriteLine(Locale.Get("Invalid Identifier Name"));
                }
            }
            else if (shouldWrite)
            {
                os.WriteLine(Locale.Get("Error: Invalid PID or Input Format"));
            }
            return(mod?.Kill(shouldWrite) ?? false);
        }
Example #2
0
 /// <summary>
 /// Kills the ExeModules on the OS.
 /// </summary>
 /// <returns><c>true</c>, if ExeModule was killed, <c>false</c> otherwise.</returns>
 /// <param name="os">The OS.</param>
 /// <param name="module">The ExeModule to kill.</param>
 /// <param name="shouldWrite">If set to <c>true</c> then success will be written to the OS.</param>
 public static bool KillExecutableModule(this Hacknet.OS os, Hacknet.ExeModule module, bool shouldWrite = false)
 {
     if (os.exes.Contains(module))
     {
         return(module.Kill(shouldWrite));
     }
     return(false);
 }
Example #3
0
 /// <summary>
 /// Kill the ExeModule.
 /// </summary>
 /// <returns><c>true</c>, if ExeModule was found, killed, and removed, <c>false</c> otherwise.</returns>
 /// <param name="module">The ExeModule to kill.</param>
 /// <param name="shouldWrite">If set to <c>true</c> then success will be written to the OS.</param>
 public static bool Kill(this Hacknet.ExeModule module, bool shouldWrite = false)
 {
     if (!module.os.exes.Contains(module))
     {
         return(false);
     }
     if (shouldWrite)
     {
         module.os.WriteLine("Process {0} [{1}] Ended", module.PID, module.IdentifierName);
     }
     // not localized normally in game, TODO: override game localization of kill (and other commands)
     module.Killed();
     return(module.os.exes.Remove(module));
 }