Пример #1
0
 public void Write(string message)
 {
     if (ctx.InvokeRequired)
     {
         StrDelegate c = new StrDelegate(Write);
         ctx.Invoke(c, new object[] { message });
     }
     else
     {
         string backup = output.Text;
         backup += message;
         if (freezWrite)
         {
             outputBuffer += message;
             return;
         }
         output.Text = backup;
         output.Select(output.Text.Length, 0);
         output.ScrollToCaret();
         output.Select(0, 0);
         if (ctx._ipcServer != null)
         {
             ctx._ipcServer.WriteStream("tut_client_proxy", backup);
         }
     }
 }
Пример #2
0
        public static void testings()
        {
            //create delegate instances
            StrDelegate objMyDelegate = new StrDelegate(GetData1);

            Console.WriteLine("Value of str: {0}", getStr());

            ////GetData1 is called
            objMyDelegate("1 ");
            Console.WriteLine("Value of str: {0}", getStr());

            objMyDelegate += GetData2;
            ////GetData1 + GetData2 is called
            objMyDelegate("2 ");
            Console.WriteLine("Value of str: {0}", getStr());

            objMyDelegate += new StrDelegate(GetData3);
            ////GetData1 + GetData2 + GetData3 is called
            objMyDelegate("3 ");
            Console.WriteLine("Value of str: {0}", getStr());

            objMyDelegate -= GetData2;
            ////GetData1 + GetData3 is called
            objMyDelegate("4 ");
            Console.WriteLine("Value of str: {0}", getStr());

            someOtherMethod(objMyDelegate);
        }
Пример #3
0
        static void Main(string[] args)
        {
            StrDelegate sD = (string str, int a) => str + Convert.ToString(a);

            Console.WriteLine(sD("abc", 123));

            Console.ReadKey();
        }
Пример #4
0
 public SrcDir(string aDirpath, StrDelegate _LogMethod)
 {
     Dirpath = aDirpath;
     LogMethood = _LogMethod;
     Directories = new List<SrcDir>();
     Files = new List<SrcFile>();
     ScanDir(Dirpath);
 }
Пример #5
0
 private void SetOutputText(string text)
 {
     if (ctx.InvokeRequired)
     {
         StrDelegate c = new StrDelegate(SetOutputText);
         ctx.Invoke(c, new object[] { text });
         return;
     }
     text        = text.Replace("\n", Environment.NewLine);
     output.Text = text;
 }
Пример #6
0
 public void SetTitle(string title)
 {
     if (ctx.InvokeRequired)
     {
         StrDelegate c = new StrDelegate(SetTitle);
         ctx.Invoke(c, new object[] { title });
     }
     else
     {
         ctx.Text = title;
     }
 }
Пример #7
0
 public void SetPrompt(string text)
 {
     if (ctx.InvokeRequired)
     {
         StrDelegate c = new StrDelegate(SetPrompt);
         ctx.Invoke(c, new object[] { text });
     }
     else
     {
         prefix     = text;
         input.Text = prefix;
         input.Select(input.Text.Length, 0);
     }
 }
Пример #8
0
        static void Main(string[] args)
        {
            StrDelegate sD = delegate(string str)
            {
                if (str == null)
                {
                    throw new Exception("Строка отсутствует");
                }
                else
                {
                    return(str.Length);
                }
            };

            Console.WriteLine(sD(""));

            Console.ReadKey();
        }
Пример #9
0
        private static string TryGetGameInstallDir()
        {
            var cp77BinDir = "";

#pragma warning disable CA1416
#if _WINDOWS
            var cp77exe = "";
            // check for CP77_DIR environment variable first
            var CP77_DIR = System.Environment.GetEnvironmentVariable("CP77_DIR", EnvironmentVariableTarget.User);
            if (!string.IsNullOrEmpty(CP77_DIR) && new DirectoryInfo(CP77_DIR).Exists)
            {
                cp77BinDir = Path.Combine(CP77_DIR, "bin", "x64");
            }

            if (File.Exists(Path.Combine(cp77BinDir, "Cyberpunk2077.exe")))
            {
                return(cp77BinDir);
            }

            // else: look for install location
            const string uninstallkey  = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
            const string uninstallkey2 = "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
            const string gameName      = "Cyberpunk 2077";
            const string exeName       = "Cyberpunk2077.exe";
            var          exePath       = "";
            StrDelegate  strDelegate   = msg => cp77exe = msg;

            try
            {
                Parallel.ForEach(Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallkey)?.GetSubKeyNames(), item =>
                {
                    var programName = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallkey + item)
                                      ?.GetValue("DisplayName");
                    var installLocation = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallkey + item)
                                          ?.GetValue("InstallLocation");
                    if (programName != null && installLocation != null)
                    {
                        if (programName.ToString().Contains(gameName) ||
                            programName.ToString().Contains(gameName))
                        {
                            exePath = Directory.GetFiles(installLocation.ToString(), exeName,
                                                         SearchOption.AllDirectories).First();
                        }
                    }

                    strDelegate.Invoke(exePath);
                });
                Parallel.ForEach(Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallkey2)?.GetSubKeyNames(), item =>
                {
                    var programName = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallkey2 + item)
                                      ?.GetValue("DisplayName");
                    var installLocation = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(uninstallkey2 + item)
                                          ?.GetValue("InstallLocation");
                    if (programName != null && installLocation != null)
                    {
                        if (programName.ToString().Contains(gameName) ||
                            programName.ToString().Contains(gameName))
                        {
                            if (Directory.Exists(installLocation.ToString()))
                            {
                                exePath = Directory.GetFiles(installLocation.ToString(), exeName,
                                                             SearchOption.AllDirectories).First();
                            }
                        }
                    }

                    strDelegate.Invoke(exePath);
                });

                if (File.Exists(cp77exe))
                {
                    cp77BinDir = new FileInfo(cp77exe).Directory.FullName;
                }
            }
            catch (Exception)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(cp77BinDir))
            {
                return(null);
            }

            if (!File.Exists(Path.Combine(cp77BinDir, "Cyberpunk2077.exe")))
            {
                return(null);
            }
#endif
#pragma warning restore CA1416

            return(cp77BinDir);
        }
        private void exeSearcherSlave_DoWork()
        {
            const string uninstallkey  = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
            const string uninstallkey2 = "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
            //var w3 = "";
            //var wcc = "";
            var cp77 = "";

            try
            {
                //StrDelegate w3del = msg => witcherexe = msg;
                //StrDelegate wccdel = msg => wccLiteexe = msg;
                StrDelegate cp77del = msg => _cp77Eexe = msg;

                Parallel.ForEach(Registry.LocalMachine.OpenSubKey(uninstallkey)?.GetSubKeyNames(), item =>
                {
                    var programName = Registry.LocalMachine.OpenSubKey(uninstallkey + item)
                                      ?.GetValue("DisplayName");
                    var installLocation = Registry.LocalMachine.OpenSubKey(uninstallkey + item)
                                          ?.GetValue("InstallLocation");
                    if (programName != null && installLocation != null)
                    {
                        //if (programName.ToString().Contains("Witcher 3 Mod Tools"))
                        //{
                        //    if (File.Exists(installLocation.ToString()))
                        //    {
                        //        wcc = Directory.GetFiles(installLocation.ToString(), "wcc_lite.exe",
                        //            SearchOption.AllDirectories).First();
                        //    }
                        //}

                        //if (programName.ToString().Contains("The Witcher 3 - Wild Hunt") ||
                        //    programName.ToString().Contains("The Witcher 3: Wild Hunt"))
                        //{
                        //    if (File.Exists(installLocation.ToString()))
                        //    {
                        //        w3 = Directory.GetFiles(installLocation.ToString(), "witcher3.exe",
                        //            SearchOption.AllDirectories).First();
                        //    }
                        //}

                        if (programName.ToString().Contains("Cyberpunk 2077"))
                        {
                            if (Directory.Exists(installLocation.ToString()))
                            {
                                if (File.Exists(installLocation.ToString()))
                                {
                                    cp77 = Directory.GetFiles(installLocation.ToString(), "Cyberpunk2077.exe",
                                                              SearchOption.AllDirectories).First();
                                }
                            }
                        }
                    }

                    //w3del.Invoke(w3);
                    //wccdel.Invoke(wcc);
                });
                Parallel.ForEach(Registry.LocalMachine.OpenSubKey(uninstallkey2)?.GetSubKeyNames(), item =>
                {
                    var programName = Registry.LocalMachine.OpenSubKey(uninstallkey2 + item)
                                      ?.GetValue("DisplayName");
                    var installLocation = Registry.LocalMachine.OpenSubKey(uninstallkey2 + item)
                                          ?.GetValue("InstallLocation");
                    if (programName != null && installLocation != null)
                    {
                        //if (programName.ToString().Contains("Witcher 3 Mod Tools"))
                        //{
                        //    if (Directory.Exists(installLocation.ToString()))
                        //    {
                        //        wcc = Directory.GetFiles(installLocation.ToString(), "wcc_lite.exe",
                        //            SearchOption.AllDirectories).First();
                        //    }
                        //}

                        //if (programName.ToString().Contains("The Witcher 3 - Wild Hunt") ||
                        //    programName.ToString().Contains("The Witcher 3: Wild Hunt"))
                        //{
                        //    if (Directory.Exists(installLocation.ToString()))
                        //    {
                        //        w3 = Directory.GetFiles(installLocation.ToString(), "witcher3.exe",
                        //        SearchOption.AllDirectories).First();
                        //    }
                        //}

                        if (programName.ToString().Contains("Cyberpunk 2077"))
                        {
                            if (Directory.Exists(installLocation.ToString()))
                            {
                                cp77 = Directory.GetFiles(installLocation.ToString(), "Cyberpunk2077.exe",
                                                          SearchOption.AllDirectories).First();
                            }
                        }
                    }

                    //w3del.Invoke(w3);
                    //wccdel.Invoke(wcc);
                    cp77del.Invoke(cp77);
                });
            }
            catch (Exception)
            {
                // TODO: Are we intentionally swallowing this?
            }

            //if (File.Exists(witcherexe))
            //{
            //    W3ExePath = witcherexe;
            //}

            //if (File.Exists(wccLiteexe))
            //{
            //    WccLitePath = wccLiteexe;
            //}

            if (File.Exists(_cp77Eexe))
            {
                CP77ExePath = _cp77Eexe;
            }

            // get the depot path
            // if depot path is empty, get the r4data from wcc_lite
            //if (string.IsNullOrEmpty(_settingsManager.DepotPath) || !Directory.Exists(_settingsManager.DepotPath))
            //{
            //    if (File.Exists(wccLiteexe) && Path.GetExtension(wccLiteexe) == ".exe" && wccLiteexe.Contains("wcc_lite.exe"))
            //    {
            //        var directoryInfo = new FileInfo(wccLiteexe).Directory;
            //        var wccDir = directoryInfo?.Parent?.Parent;
            //        if (wccDir != null)
            //        {
            //            var wccR4data = Path.Combine(wccDir.FullName, "r4data");
            //            if (Directory.Exists(wccR4data))
            //            {
            //                _settingsManager.DepotPath = wccR4data;
            //            }
            //        }
            //    }
            //}
        }
 public void StringCon(StrDelegate Fname, StrDelegate Lname)
 {
     Console.WriteLine(Fname() + " " + Lname());
 }