private CutLists GetFileMatches() { var items = _fileResultsListView.SelectedItems; if (items.Count == 0) { return(null); } var result = new CutLists(); foreach (var item in items) { var listViewItem = item as ListViewItem; if (listViewItem == null) { continue; } var displayInfo = listViewItem.Content as SearchResultFileDisplayInfo; if (displayInfo == null) { continue; } if (displayInfo.FileIndex >= (uint)_resultDemos.Count) { continue; } var filePath = _resultDemos[(int)displayInfo.FileIndex].FilePath; if (!App.IsValidWriteProtocol(App.GetProtocolFromFilePath(filePath))) { continue; } var matches = _results.FindAll(c => c.DemoInputIndex == displayInfo.FileIndex); var fileCuts = new FileCuts(); fileCuts.FilePath = filePath; foreach (var match in matches) { var cut = new UDT_DLL.Cut(); cut.GameStateIndex = (int)match.GameStateIndex; cut.StartTimeMs = match.StartTimeMs; cut.EndTimeMs = match.EndTimeMs; fileCuts.Cuts.Add(cut); } result.FileCuts.Add(fileCuts); } return(result); }
private void OnCutByTimeClicked() { var demo = _app.SelectedDemo; if (demo == null) { _app.LogError("No demo was selected. Please select one to proceed."); return; } if (!App.IsValidWriteProtocol(demo.ProtocolNumber)) { _app.LogError("Can't write demos of that protocol"); return; } int startTime = -1; if (!App.GetTimeSeconds(_startTimeEditBox.Text, out startTime)) { _app.LogError("Invalid start time. Format must be (seconds) or (minutes:seconds)"); return; } int endTime = -1; if (!App.GetTimeSeconds(_endTimeEditBox.Text, out endTime)) { _app.LogError("Invalid end time. Format must be (seconds) or (minutes:seconds)"); return; } if (startTime >= endTime) { _app.LogError("Invalid times. Start time must be strictly inferior to end time."); return; } var gameStateCount = demo.GameStateFileOffsets.Count; int gameStateIndex = -1; if (!int.TryParse(_gameStateIndexEditBox.Text, out gameStateIndex)) { gameStateIndex = -1; } uint fileOffset = 0; if (!demo.Analyzed || gameStateCount == 0) { if (gameStateIndex != 0) { _app.LogError("You selected a non-0 GameState index but UDT doesn't know the file offset of it, if it even exists. Please analyze the demo first to proceed."); return; } } else if (gameStateCount > 0) { if (gameStateCount > 1 && gameStateIndex >= gameStateCount) { _app.LogError("Invalid GameState index. Valid range for this demo: {0}-{1}", 0, demo.GameStateFileOffsets.Count - 1); return; } if (gameStateCount == 1 && gameStateIndex != 0) { _gameStateIndexEditBox.Text = "0"; gameStateIndex = 0; _app.LogWarning("Invalid GameState index. The only valid value for this demo is 0. UDT set it right for you."); } fileOffset = demo.GameStateFileOffsets[gameStateIndex]; } if (demo.Analyzed && gameStateIndex >= 0 && gameStateIndex < demo.GameStateSnapshotTimesMs.Count) { var times = demo.GameStateSnapshotTimesMs[gameStateIndex]; if (startTime > times.Item2 / 1000) { _app.LogError("Invalid start time: it comes after the last snapshot of that GameState."); return; } if (endTime < times.Item1 / 1000) { _app.LogError("Invalid end time: it comes before the first snapshot of that GameState."); return; } } _app.DisableUiNonThreadSafe(); _app.JoinJobThread(); _app.SaveConfig(); var info = new CutByTimeInfo(); info.GameStateIndex = gameStateIndex; info.FileOffset = fileOffset; info.FilePath = demo.FilePath; info.StartTime = startTime; info.EndTime = endTime; _app.StartJobThread(DemoCutByTimeThread, info); }