public static bool CutDemosByPattern(ArgumentResources resources, ref udtParseArg parseArg, List<string> filePaths, udtPatternInfo[] patterns, CutByPatternOptions options) { var timer = new Stopwatch(); timer.Start(); var fileCount = filePaths.Count; if(fileCount <= MaxBatchSizeCutting) { var result = CutDemosByPatternImpl(resources, ref parseArg, filePaths, patterns, options); PrintExecutionTime(timer); return result; } var oldProgressCb = parseArg.ProgressCb; var progressBase = 0.0f; var progressRange = 0.0f; var fileIndex = 0; var newParseArg = parseArg; newParseArg.ProgressCb = delegate(float progress, IntPtr userData) { var realProgress = progressBase + progressRange * progress; oldProgressCb(realProgress, userData); }; var demos = new List<DemoInfo>(); var batchCount = (fileCount + MaxBatchSizeCutting - 1) / MaxBatchSizeCutting; var filesPerBatch = fileCount / batchCount; var success = true; for(int i = 0; i < batchCount; ++i) { progressBase = (float)fileIndex / (float)fileCount; var currentFileCount = (i == batchCount - 1) ? (fileCount - fileIndex) : filesPerBatch; var currentFiles = filePaths.GetRange(fileIndex, currentFileCount); progressRange = (float)currentFileCount / (float)fileCount; var newResources = new ArgumentResources(); CutDemosByPatternImpl(newResources, ref newParseArg, currentFiles, patterns, options); fileIndex += currentFileCount; if(Marshal.ReadInt32(parseArg.CancelOperation) != 0) { success = false; break; } } resources.Free(); PrintExecutionTime(timer); return success; }
private static bool CutDemosByPatternImpl(ArgumentResources resources, ref udtParseArg parseArg, List<string> filePaths, udtPatternInfo[] patterns, CutByPatternOptions options) { var errorCodeArray = new Int32[filePaths.Count]; var filePathArray = new IntPtr[filePaths.Count]; for(var i = 0; i < filePaths.Count; ++i) { filePathArray[i] = Marshal.StringToHGlobalAnsi(Path.GetFullPath(filePaths[i])); resources.GlobalAllocationHandles.Add(filePathArray[i]); } parseArg.PlugInCount = 0; parseArg.PlugIns = IntPtr.Zero; var pinnedFilePaths = new PinnedObject(filePathArray); var pinnedErrorCodes = new PinnedObject(errorCodeArray); var multiParseArg = new udtMultiParseArg(); multiParseArg.FileCount = (UInt32)filePathArray.Length; multiParseArg.FilePaths = pinnedFilePaths.Address; multiParseArg.OutputErrorCodes = pinnedErrorCodes.Address; multiParseArg.MaxThreadCount = (UInt32)options.MaxThreadCount; var playerNameUnmanaged = IntPtr.Zero; if(!string.IsNullOrEmpty(options.PlayerName)) { playerNameUnmanaged = Marshal.StringToHGlobalAnsi(options.PlayerName); resources.GlobalAllocationHandles.Add(playerNameUnmanaged); } var pinnedPatterns = new PinnedObject(patterns); var cutByPatternArg = new udtCutByPatternArg(); cutByPatternArg.StartOffsetSec = (UInt32)options.StartOffset; cutByPatternArg.EndOffsetSec = (UInt32)options.EndOffset; cutByPatternArg.Patterns = pinnedPatterns.Address; cutByPatternArg.PatternCount = (UInt32)patterns.Length; cutByPatternArg.PlayerIndex = options.PlayerIndex; cutByPatternArg.PlayerName = playerNameUnmanaged; cutByPatternArg.Flags = 0; if(options.MergeCutSections) { cutByPatternArg.Flags |= (UInt32)udtCutByPatternArgFlags.MergeCutSections; } resources.PinnedObjects.Add(pinnedPatterns); resources.PinnedObjects.Add(pinnedFilePaths); resources.PinnedObjects.Add(pinnedErrorCodes); udtErrorCode result = udtErrorCode.OperationFailed; try { result = udtCutDemoFilesByPattern(ref parseArg, ref multiParseArg, ref cutByPatternArg); } finally { resources.Free(); } return result == udtErrorCode.None; }
public static bool CutDemosByMultiRail(ref udtParseArg parseArg, List<string> filePaths, udtCutByMultiRailArg rules, CutByPatternOptions options) { var resources = new ArgumentResources(); var patterns = new udtPatternInfo[1]; if(!CreateMultiRailPatternInfo(ref patterns[0], resources, rules)) { return false; } return CutDemosByPattern(resources, ref parseArg, filePaths, patterns, options); }