Example #1
0
        public static Task <ProcessAsyncHelper.ProcessResult> Bash(this string cmd, bool shouldWaitToExit = false)
        {
            var escapedArgs = cmd.Replace("\"", "\\\"");

            return(ProcessAsyncHelper.ExecuteShellCommand("/bin/bash", new[]
            {
                $"-c \"{escapedArgs}\""
            }, shouldWaitToExit, CancellationToken.None));
        }
Example #2
0
        private async Task <string> ConvertFileToPdf(string filePath)
        {
            var exePath = "chordpro.exe";

            // Create temp config file path
            var configurationFilePath = Path.GetTempPath() + Guid.NewGuid() + ".json";

            File.WriteAllText(configurationFilePath, _configurationService.LoadConfigurationFileText());

            //var configFilePath = _globalContext.ConfigFilePath;
            if (string.IsNullOrEmpty(configurationFilePath))
            {
                await ShowErrorMessage("Chordpro config file not defined");

                return(null);
            }

            var filename = Path.GetFileName(filePath);

            if (string.IsNullOrEmpty(filename))
            {
                await ShowErrorMessage("Input file not defined");

                return(null);
            }

            var directoryPath = Path.GetDirectoryName(filePath);

            if (string.IsNullOrEmpty(directoryPath))
            {
                await ShowErrorMessage("Directory not found");

                return(null);
            }

            var outputFilePath = directoryPath + "\\" + filename.Replace(".cho", ".pdf");
            var arguments      = $"\"{filePath}\" -o \"{outputFilePath}\" --cfg \"{configurationFilePath}\"";

            if (!string.IsNullOrEmpty(TextSize))
            {
                arguments += $" --text-size={TextSize}";
            }

            var result = await ProcessAsyncHelper.ExecuteShellCommand(exePath, arguments, int.MaxValue);

            var error = result.Output;

            if (!string.IsNullOrEmpty(error))
            {
                await ShowErrorMessage(error);

                return(null);
            }

            return(outputFilePath);
        }
Example #3
0
        public async Task TestProcessHelper()
        {
            await ProcessAsyncHelper.ExecuteShellCommand("nodejs.exe", ".\\private_module\\index.js tt ss", 10000);

            Assert.True(true);
        }
Example #4
0
        private async void Btn_Build_Click(object sender, EventArgs e)
        {
            list_Logs.Items.Clear();
            list_Logs.Items.Add(Text);
            list_Logs.Items.Add("");

            string buildNumber = Path.GetRandomFileName().Replace(".", "").Substring(4);

            Log($"Build started for Legacy of Solaris (Build: {buildNumber})...");

            string repository     = Path.Combine(text_Repository.Text, "Legacy of Solaris");
            string platformString = string.Empty;
            string buildDir       = string.Empty;
            int    system         = 0;

            if (radio_Xbox360.Checked)
            {
                platformString = "Xbox 360";
                system         = 0;
            }
            else if (radio_PlayStation3.Checked)
            {
                platformString = "PlayStation 3";
                system         = 1;
            }

            if (Directory.Exists(repository))
            {
                List <string> xscripts = Directory.GetFiles(repository, "*.xscript", SearchOption.AllDirectories).ToList();
                List <string> pscripts = Directory.GetFiles(repository, "*.pscript", SearchOption.AllDirectories).ToList();

                try {
                    if (system == 0)
                    {
                        if (check_ForceParams.Checked)
                        {
                            foreach (string script in pscripts)
                            {
                                File.Move(script, Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"));
                            }
                        }
                        else
                        {
                            foreach (string script in xscripts)
                            {
                                File.Move(script, Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"));
                            }
                        }
                    }
                    else if (system == 1)
                    {
                        if (check_ForceParams.Checked)
                        {
                            foreach (string script in xscripts)
                            {
                                File.Move(script, Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"));
                            }
                        }
                        else
                        {
                            foreach (string script in pscripts)
                            {
                                File.Move(script, Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"));
                            }
                        }
                    }
                } catch { }

                if (Directory.Exists(text_BuildLocation.Text))
                {
                    buildDir = Path.Combine(text_BuildLocation.Text, $"Legacy of Solaris ({buildNumber})");
                    Directory.CreateDirectory(buildDir);
                    InterfaceState(false);
                }
                else
                {
                    Log($"Failed to build Legacy of Solaris (Build: {buildNumber})...");
                    SystemSounds.Hand.Play();
                    UnifyMessages.UnifyMessage.Show("Please specify a valid build location...",
                                                    "Path Error",
                                                    "OK",
                                                    "Error");
                    InterfaceState(true);
                    return;
                }

                if (Directory.Exists(text_GameDirectory.Text))
                {
                    List <string> directories = Directory.GetDirectories(repository, "*.arc", SearchOption.AllDirectories).ToList();
                    List <string> xfiles      = Directory.GetFiles(repository, "*.*", SearchOption.AllDirectories)
                                                .Where(s => s.ToLower().EndsWith("default.xex") ||
                                                       s.ToLower().EndsWith(".wmv") ||
                                                       s.ToLower().EndsWith(".xma")).ToList();
                    //X-Files lol
                    List <string> psfiles = Directory.GetFiles(repository, "*.*", SearchOption.AllDirectories)
                                            .Where(s => s.ToLower().EndsWith("eboot.bin") ||
                                                   s.ToLower().EndsWith(".pam") ||
                                                   s.ToLower().EndsWith(".at3")).ToList();
                    int errorCount = 0;

                    if (radio_Standalone.Checked)
                    {
                        foreach (string archive in directories)
                        {
                            Log($"Repacking {Path.GetFileName(archive)} to Legacy of Solaris (Build: {buildNumber})...");
                            try {
                                List <string> getArchive = Directory.GetFiles(text_GameDirectory.Text, Path.GetFileName(archive), SearchOption.AllDirectories).ToList();
                                string        arcPath    = getArchive[0].Remove(0, text_GameDirectory.Text.Length).Substring(1);
                                Directory.CreateDirectory(Path.Combine(buildDir, Path.GetDirectoryName(arcPath)));
                                MergeARCs(getArchive[0], archive, Path.Combine(buildDir, arcPath), system);
                            } catch {
                                Log($"Failed to repack '{Path.GetFileName(archive)}' to Legacy of Solaris (Build: {buildNumber})...");
                                SystemSounds.Hand.Play();
                                errorCount++;
                            }
                        }

                        var metadataWrite   = File.Create(Path.Combine(buildDir, "mod.ini"));
                        var metadataSession = new UTF8Encoding(true).GetBytes("Title=\"Legacy of Solaris\"\n" +
                                                                              $"Version=\"{buildNumber}\"\n" +
                                                                              $"Date=\"{DateTime.Now.ToString("dd/MM/yyyy")}\"\n" +
                                                                              $"Author=\"Lost Legacy Team\"\n" +
                                                                              $"Platform=\"{platformString}\"\n" +
                                                                              "Merge=\"False\"");
                        metadataWrite.Write(metadataSession, 0, metadataSession.Length);
                        metadataWrite.Close();
                    }
                    else if (radio_Merge.Checked)
                    {
                        foreach (string archive in directories)
                        {
                            Log($"Repacking {Path.GetFileName(archive)} to Legacy of Solaris (Build: {buildNumber})...");
                            try {
                                List <string> getArchive = Directory.GetFiles(text_GameDirectory.Text, Path.GetFileName(archive), SearchOption.AllDirectories).ToList();
                                string        arcPath    = getArchive[0].Remove(0, text_GameDirectory.Text.Length).Substring(1);
                                Directory.CreateDirectory(Path.Combine(buildDir, Path.GetDirectoryName(arcPath)));

                                if (Directory.GetDirectories(archive, "_core", SearchOption.AllDirectories).Length > 0)
                                {
                                    foreach (string core in Directory.GetDirectories(archive, "_core", SearchOption.AllDirectories))
                                    {
                                        if (system == 0)
                                        {
                                            Directory.Move(core, Path.Combine(Path.GetDirectoryName(core), "xenon"));
                                        }
                                        else if (system == 1)
                                        {
                                            Directory.Move(core, Path.Combine(Path.GetDirectoryName(core), "ps3"));
                                        }
                                    }
                                }
                                else if (Directory.GetDirectories(archive, "xenon", SearchOption.AllDirectories).Length > 0)
                                {
                                    foreach (string core in Directory.GetDirectories(archive, "xenon", SearchOption.AllDirectories))
                                    {
                                        if (system == 1)
                                        {
                                            Directory.Move(core, Path.Combine(Path.GetDirectoryName(core), "ps3"));
                                        }
                                    }
                                }
                                else if (Directory.GetDirectories(archive, "ps3", SearchOption.AllDirectories).Length > 0)
                                {
                                    foreach (string core in Directory.GetDirectories(archive, "ps3", SearchOption.AllDirectories))
                                    {
                                        if (system == 0)
                                        {
                                            Directory.Move(core, Path.Combine(Path.GetDirectoryName(core), "xenon"));
                                        }
                                    }
                                }

                                await ProcessAsyncHelper.ExecuteShellCommand(Program.arctool,
                                                                             $"-i \"{archive}\" -c \"{Path.Combine(buildDir, arcPath)}\"",
                                                                             Application.StartupPath,
                                                                             100000);

                                if (Directory.GetDirectories(archive, "xenon", SearchOption.AllDirectories).Length > 0)
                                {
                                    foreach (string core in Directory.GetDirectories(archive, "xenon", SearchOption.AllDirectories))
                                    {
                                        Directory.Move(core, Path.Combine(Path.GetDirectoryName(core), "_core"));
                                    }
                                }
                                else if (Directory.GetDirectories(archive, "ps3", SearchOption.AllDirectories).Length > 0)
                                {
                                    foreach (string core in Directory.GetDirectories(archive, "ps3", SearchOption.AllDirectories))
                                    {
                                        Directory.Move(core, Path.Combine(Path.GetDirectoryName(core), "_core"));
                                    }
                                }
                            } catch {
                                Log($"Failed to repack '{Path.GetFileName(archive)}' to Legacy of Solaris (Build: {buildNumber})...");
                                SystemSounds.Hand.Play();
                                errorCount++;
                            }
                        }

                        var metadataWrite   = File.Create(Path.Combine(buildDir, "mod.ini"));
                        var metadataSession = new UTF8Encoding(true).GetBytes("Title=\"Legacy of Solaris\"\n" +
                                                                              $"Version=\"{buildNumber}\"\n" +
                                                                              $"Date=\"{DateTime.Now.ToString("dd/MM/yyyy")}\"\n" +
                                                                              $"Author=\"Lost Legacy Team\"\n" +
                                                                              $"Platform=\"{platformString}\"\n" +
                                                                              "Merge=\"True\"");
                        metadataWrite.Write(metadataSession, 0, metadataSession.Length);
                        metadataWrite.Close();
                    }

                    if (system == 0)
                    {
                        foreach (string content in xfiles)
                        {
                            Log($"Copying {Path.GetFileName(content)} to Legacy of Solaris (Build: {buildNumber})...");
                            try {
                                List <string> getFile  = Directory.GetFiles(text_GameDirectory.Text, Path.GetFileName(content), SearchOption.AllDirectories).ToList();
                                string        filePath = getFile[0].Remove(0, text_GameDirectory.Text.Length).Substring(1);
                                Directory.CreateDirectory(Path.Combine(buildDir, Path.GetDirectoryName(filePath)));
                                File.Copy(content, Path.Combine(buildDir, filePath), true);
                            } catch {
                                Log($"Failed to copy '{Path.GetFileName(content)}' to Legacy of Solaris (Build: {buildNumber})...");
                                SystemSounds.Hand.Play();
                                errorCount++;
                            }
                        }
                    }
                    else if (system == 1)
                    {
                        foreach (string content in psfiles)
                        {
                            Log($"Copying {Path.GetFileName(content)} to Legacy of Solaris (Build: {buildNumber})...");
                            try {
                                List <string> getFile  = Directory.GetFiles(text_GameDirectory.Text, Path.GetFileName(content), SearchOption.AllDirectories).ToList();
                                string        filePath = getFile[0].Remove(0, text_GameDirectory.Text.Length).Substring(1);
                                Directory.CreateDirectory(Path.Combine(buildDir, Path.GetDirectoryName(filePath)));
                                File.Copy(content, Path.Combine(buildDir, filePath), true);
                            } catch {
                                Log($"Failed to copy '{Path.GetFileName(content)}' to Legacy of Solaris (Build: {buildNumber})...");
                                SystemSounds.Hand.Play();
                                errorCount++;
                            }
                        }
                    }

                    if (errorCount == 0)
                    {
                        Log($"Legacy of Solaris (Build: {buildNumber}) was built successfully...");
                        SystemSounds.Asterisk.Play();
                    }
                    else
                    {
                        Log($"Failed to build Legacy of Solaris (Build: {buildNumber})...");
                        SystemSounds.Hand.Play();
                        try {
                            if (Directory.Exists(buildDir))
                            {
                                DirectoryInfo buildData = new DirectoryInfo(buildDir);
                                foreach (FileInfo file in buildData.GetFiles())
                                {
                                    file.Delete();
                                }
                                foreach (DirectoryInfo directory in buildData.GetDirectories())
                                {
                                    directory.Delete(true);
                                }
                                Directory.Delete(buildDir);
                            }
                        } catch { return; }
                    }
                    InterfaceState(true);
                }
                else
                {
                    Log($"Failed to build Legacy of Solaris (Build: {buildNumber})...");
                    SystemSounds.Hand.Play();
                    UnifyMessages.UnifyMessage.Show("Please specify a valid game directory...",
                                                    "Path Error",
                                                    "OK",
                                                    "Error");
                    InterfaceState(true);
                    return;
                }

                try {
                    if (system == 0)
                    {
                        if (check_ForceParams.Checked)
                        {
                            foreach (string script in pscripts)
                            {
                                File.Move(Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"), script);
                            }
                        }
                        else
                        {
                            foreach (string script in xscripts)
                            {
                                File.Move(Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"), script);
                            }
                        }
                    }
                    else if (system == 1)
                    {
                        if (check_ForceParams.Checked)
                        {
                            foreach (string script in xscripts)
                            {
                                File.Move(Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"), script);
                            }
                        }
                        else
                        {
                            foreach (string script in pscripts)
                            {
                                File.Move(Path.Combine(Path.GetDirectoryName(script), $"{Path.GetFileNameWithoutExtension(script)}.lub"), script);
                            }
                        }
                    }
                } catch { }
            }
            else
            {
                Log($"Failed to build Legacy of Solaris (Build: {buildNumber})...");
                SystemSounds.Hand.Play();
                string invalidRepo = UnifyMessages.UnifyMessage.Show("Invalid repository... Please ensure the selected path is named " +
                                                                     "either 'LoS-Developers' or 'LoS-Developers-master.' If neither " +
                                                                     "exist, do you want to obtain the correct one?",
                                                                     "Repository Error",
                                                                     "YesNo",
                                                                     "Error");
                if (invalidRepo == "Yes")
                {
                    Process.Start("https://github.com/lost-legacy-team/LoS-Developers");
                }
                InterfaceState(true);
                return;
            }
        }
Example #5
0
        static async Task Main(string[] args)
        {
            if (File.Exists("output2.mp4"))
            {
                File.Delete("output2.mp4");
            }


            string token = null;

            using (var client = new HttpClient())
            {
                token = await client.GetStringAsync(
                    "https://spitball-function-dev2.azurewebsites.net/api/studyRoom/code/?code=/Zcx/KGplZt2tX5uh0ljh15eeaqaFBHMqjd9cz4LI0wZTsv4c380gw==");
            }

            var z3 = await "killall Xvfb".Bash(true);

            //export DISPLAY=\":99\"
            await "Xvfb :99 -screen 0 1920x1080x24 &".Bash(true);
            await "xdpyinfo -display :99 >/dev/null 2>&1 && echo \"In use\" || echo \"Free\"".Bash(true);
            var x   = new CancellationTokenSource();
            var url =
                $"https://dev.spitball.co/studyroom/7b0d6988-81ca-40b9-8d70-ac2800cecda6/?token={token}&recordingBot=true";

            await "killall chrome".Bash(true);
            var z4 = await ProcessAsyncHelper.ExecuteShellCommand("google-chrome", new[]
            {
                "--remote-debugging-port=9223",
                "--no-first-run",
                "--start-fullscreen",
                "--window-position=0,0",
                "--window-size=1920,1080",
                //"--start-maximized",
                //"--full-screen",
                "--kiosk",
                "--disable-gpu",
                "--enable-logging --v=1",
                "--no-sandbox",
                // "--headless",
                // "--remote-debugging-address=0.0.0.0",
                url
            }
                                                                  , CancellationToken.None);



            var z = await ProcessAsyncHelper.ExecuteShellCommand("ffmpeg", new[]
            {
                "-y -nostdin",
                "-video_size 1920x1080 -framerate 30 -f x11grab",
                "-draw_mouse 0",
                "-i :99",
                "-c:v libx264 -crf 0 -preset ultrafast",
                "output2.mkv",
            }, x.Token);

            await Task.Delay(TimeSpan.FromSeconds(45));

            x.Cancel();


            var z22222 = await ProcessAsyncHelper.ExecuteShellCommand("ffmpeg", new[]
            {
                "-y -nostdin",
                // "-video_size 1920x1080 -framerate 24 -f x11grab",
                "-i output2.mkv",
                "-c:v libx264 -crf 23 -pix_fmt yuv420p",
                "output2.mp4",
            }, true, CancellationToken.None);


            //Create a unique name for the container
            //string containerName = "quickstartblobs" + Guid.NewGuid().ToString();

            // Create the container and return a container client object
            //BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("spitball-user");
            //var blobClient = containerClient.GetBlobClient("test.mp4");
            if (File.Exists("output2.mp4"))
            {
                await using FileStream uploadFileStream = File.OpenRead("output2.mp4");
                Debug.WriteLine(uploadFileStream.Length);
                //await blobClient.UploadAsync(uploadFileStream, true);
                uploadFileStream.Close();
            }

            // Process.Start(command);
            //foreach (var process in Process.GetProcesses())
            //{

            //    Console.WriteLine($"Counter: {process.ProcessName}");
            //}
            var counter = 0;
            var max     = args.Length != 0 ? Convert.ToInt32(args[0]) : -1;

            while (max == -1 || counter < max)
            {
                Console.WriteLine($"Counter: {++counter}");
                await Task.Delay(1000);
            }
        }