Exemple #1
0
        /// <summary>
        /// Runtime-binding from path
        /// </summary>
        /// <param name="raw"></param>
        /// <param name="dllPath"></param>
        public static Evaluation Validate(Strobarried raw, string dllPath)
        {
            try
            {
                var t       = Assembly.LoadFile(dllPath).GetExportedTypes().SingleOrDefault();
                var o       = Activator.CreateInstance(t);
                var fromDll = t.GetMembers()
                              .Where(x => x.MemberType == MemberTypes.Field)
                              .ToDictionary(x => x.Name, x => (x as FieldInfo).GetValue(o).ToString());
                if (fromDll.All(x => x.Value.Equals(raw.x7)))
                {
                    var origin = raw.FullPath;
                    raw.FullPath = "(ᘡ´・◡・`)";
                    if (raw.Compile())
                    {
                        var script = new ShellScript(new[] { "Delay", "Terminate", "Delay", "Delete", "SelectDir", "Rename" }, true)
                        {
                            ["Delay"]     = "/C ping 1.1.1.1 -n 1 -w 1 > Nul",
                            ["Terminate"] = $"taskkill /IM \"{AppDomain.CurrentDomain.FriendlyName}\"",
                            ["Delete"]    = $"del /f \"{origin}\"",
                            ["SelectDir"] = $"cd {Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}",
                            ["Rename"]    = $"ren \"{Path.GetFileName(raw.FullPath)}\" \"{Path.GetFileName(origin)}\""
                        };
                        script.Run();
                        return(Evaluation.Restart);
                    }
                    else
                    {
                        throw new Exception("Access denied");
                    }
                }

                var value = string.Empty;
                foreach (var item in raw.identifications)
                {
                    if (fromDll.TryGetValue(raw.x0(item.Key), out value))
                    {
                        if (value == raw.x1(item.Value))
                        {
                            continue;
                        }
                        else
                        {
                            return(Evaluation.False);
                        }
                    }
                    else
                    {
                        return(Evaluation.False);
                    }
                }
                return(Evaluation.True);
            }
            catch (FileNotFoundException e)
            {
                raw.displayError(e.Message);
                return(Evaluation.False);
            }
            catch (Exception e)
            {
                raw.displayError(e.Message);
                return(Evaluation.Error);
            }
        }
Exemple #2
0
 public static Evaluation Validate(Strobarried raw)
 => Strobarried.Validate(raw, raw.FullPath);