/// <summary>
        /// Generate the VirtualDub jobs file.
        /// </summary>
        private void GenerateVirtualDubScript()
        {
            string[] tgaFiles         = Directory.GetFiles(_config.RawFilesDestination, _config.OutputFilename + "*.tga");
            string   videoPath        = GetOuputFilePath().Replace("\\", "\\\\");
            string   firstTgaFilePath = GetFirstTgaPath();
            string   wavFilePath      = RawFullPath + ".wav";
            string   vdScript         = string.Format(Properties.Resources.vd, firstTgaFilePath, wavFilePath, _config.FrameRate, tgaFiles.Length, videoPath);
            string   virtualDubPath   = VirtualDubService.GetVirtualDubPath();

            if (Directory.Exists(virtualDubPath))
            {
                File.WriteAllText(virtualDubPath + Path.DirectorySeparatorChar + "csgodm.jobs", vdScript);
            }
        }
Exemple #2
0
        /// <summary>
        /// Generate the VirtualDub jobs file.
        /// </summary>
        private void GenerateVirtualDubScript()
        {
            string tgaDirectoryPath = GetTgaDirectoryPath();

            if (!Directory.Exists(tgaDirectoryPath))
            {
                throw new Exception("Directory containing TGA files does not exists");
            }

            string[] tgaFiles = Directory.GetFiles(tgaDirectoryPath, "*.tga");
            if (tgaFiles.Length == 0)
            {
                throw new Exception("No TGA files found");
            }

            string videoPath = EscapePath(GetOuputFilePath());

            if (videoPath == null)
            {
                throw new Exception("Ouput directory does not exists");
            }

            string firstTgaFilePath = EscapePath(GetFirstTgaPath());

            if (!File.Exists(firstTgaFilePath))
            {
                throw new Exception("TGA file 00000.tga not found");
            }

            string wavFilePath = EscapePath(GetLastWavFilePath());

            if (!File.Exists(wavFilePath))
            {
                throw new Exception("WAV file not found");
            }

            string vdScript       = string.Format(Properties.Resources.vd, firstTgaFilePath, wavFilePath, _config.FrameRate, tgaFiles.Length, videoPath);
            string virtualDubPath = VirtualDubService.GetVirtualDubPath();

            if (!Directory.Exists(virtualDubPath))
            {
                throw new Exception("VirtualDub directory not found");
            }

            File.WriteAllText(virtualDubPath + Path.DirectorySeparatorChar + "csgodm.jobs", vdScript);
        }
Exemple #3
0
        /// <summary>
        /// Callback when the game is closed.
        /// </summary>
        private async Task HandleGameClosed()
        {
            OnGameClosed?.Invoke();

            // delete VDM file, we don't need it anymore
            string vdmPath = _config.Demo.GetVdmFilePath();

            if (File.Exists(vdmPath))
            {
                File.Delete(vdmPath);
            }

            // delete the CFG file, we don't need it anymore
            string cfgPath = GetCfgPath();

            if (File.Exists(cfgPath))
            {
                File.Delete(cfgPath);
            }

            // do not continue if TGA file not present, user may have close the game prematurely
            if (!IsFirstTgaExists())
            {
                return;
            }

            // generate a video file if the user want it
            if (_config.GenerateVideoFile)
            {
                if (_config.UseVirtualDub)
                {
                    // VirtualDub
                    GenerateVirtualDubScript();
                    ProcessStartInfo psi = new ProcessStartInfo
                    {
                        Arguments        = "/s csgodm.jobs /x",
                        FileName         = VirtualDubService.GetVirtualDubExePath(),
                        WorkingDirectory = VirtualDubService.GetVirtualDubPath(),
                    };
                    Process p = new Process
                    {
                        StartInfo = psi,
                    };
                    p.Start();
                    OnVirtualDubStarted?.Invoke();
                    await p.WaitForExitAsync();

                    OnVirtualDubClosed?.Invoke();
                    HandleEncodingEnded();
                }
                else
                {
                    // FFmpeg
                    List <string>    argsList = GetFFmpegArgs();
                    string           args     = string.Join(" ", argsList.ToArray());
                    ProcessStartInfo psi      = new ProcessStartInfo
                    {
                        Arguments       = args,
                        FileName        = FFmpegService.GetFFmpegExePath(),
                        UseShellExecute = false
                    };
                    Process p = new Process
                    {
                        StartInfo = psi,
                    };
                    OnFFmpegStarted?.Invoke();
                    p.Start();
                    await p.WaitForExitAsync();

                    OnFFmpegClosed?.Invoke();
                    HandleEncodingEnded();
                }
            }
        }