2025-10-09 12:14:38 +02:00
|
|
|
import strformat, strutils, times, os
|
2025-10-03 12:44:28 +02:00
|
|
|
import imguin/[cimgui, glfw_opengl, simple]
|
|
|
|
|
import ../../utils/[appImGui, colors]
|
2025-10-07 21:16:17 +02:00
|
|
|
import ../../../common/[types, utils]
|
2025-10-03 12:44:28 +02:00
|
|
|
|
2025-10-07 21:16:17 +02:00
|
|
|
type
|
|
|
|
|
DownloadsComponent* = ref object of RootObj
|
|
|
|
|
title: string
|
2025-10-09 12:14:38 +02:00
|
|
|
items*: seq[LootItem]
|
2025-10-07 21:16:17 +02:00
|
|
|
selectedIndex: int
|
|
|
|
|
|
2025-10-03 12:44:28 +02:00
|
|
|
|
2025-10-07 21:16:17 +02:00
|
|
|
proc LootDownloads*(title: string): DownloadsComponent =
|
|
|
|
|
result = new DownloadsComponent
|
2025-10-03 12:44:28 +02:00
|
|
|
result.title = title
|
2025-10-07 21:16:17 +02:00
|
|
|
result.items = @[]
|
|
|
|
|
result.selectedIndex = -1
|
|
|
|
|
|
|
|
|
|
proc draw*(component: DownloadsComponent, showComponent: ptr bool) =
|
2025-10-03 12:44:28 +02:00
|
|
|
igBegin(component.title, showComponent, 0)
|
2025-10-07 21:16:17 +02:00
|
|
|
defer: igEnd()
|
|
|
|
|
|
|
|
|
|
var availableSize: ImVec2
|
|
|
|
|
igGetContentRegionAvail(addr availableSize)
|
|
|
|
|
let textSpacing = igGetStyle().ItemSpacing.x
|
|
|
|
|
|
|
|
|
|
# Left panel (file table)
|
|
|
|
|
let childFlags = ImGui_ChildFlags_ResizeX.int32 or ImGui_ChildFlags_NavFlattened.int32
|
|
|
|
|
if igBeginChild_Str("##Left", vec2(availableSize.x * 0.66f, 0.0f), childFlags, ImGui_WindowFlags_None.int32):
|
|
|
|
|
|
|
|
|
|
let tableFlags = (
|
|
|
|
|
ImGui_TableFlags_Resizable.int32 or
|
|
|
|
|
ImGui_TableFlags_Reorderable.int32 or
|
|
|
|
|
ImGui_TableFlags_Hideable.int32 or
|
|
|
|
|
ImGui_TableFlags_HighlightHoveredColumn.int32 or
|
|
|
|
|
ImGui_TableFlags_RowBg.int32 or
|
|
|
|
|
ImGui_TableFlags_BordersV.int32 or
|
|
|
|
|
ImGui_TableFlags_BordersH.int32 or
|
|
|
|
|
ImGui_TableFlags_ScrollY.int32 or
|
|
|
|
|
ImGui_TableFlags_ScrollX.int32 or
|
|
|
|
|
ImGui_TableFlags_NoBordersInBodyUntilResize.int32 or
|
|
|
|
|
ImGui_TableFlags_SizingStretchSame.int32
|
|
|
|
|
)
|
|
|
|
|
|
2025-10-09 12:14:38 +02:00
|
|
|
let cols: int32 = 6
|
2025-10-07 21:16:17 +02:00
|
|
|
if igBeginTable("##Items", cols, tableFlags, vec2(0.0f, 0.0f), 0.0f):
|
2025-10-09 12:14:38 +02:00
|
|
|
igTableSetupColumn("ID", ImGuiTableColumnFlags_None.int32, 0.0f, 0)
|
|
|
|
|
igTableSetupColumn("AgentID", ImGuiTableColumnFlags_DefaultHide.int32, 0.0f, 0)
|
|
|
|
|
igTableSetupColumn("Host", ImGuiTableColumnFlags_None.int32, 0.0f, 0)
|
2025-10-07 21:16:17 +02:00
|
|
|
igTableSetupColumn("Path", ImGuiTableColumnFlags_None.int32, 0.0f, 0)
|
|
|
|
|
igTableSetupColumn("Creation Date", ImGuiTableColumnFlags_None.int32, 0.0f, 0)
|
|
|
|
|
igTableSetupColumn("Size", ImGuiTableColumnFlags_None.int32, 0.0f, 0)
|
|
|
|
|
igTableSetupScrollFreeze(0, 1)
|
|
|
|
|
igTableHeadersRow()
|
|
|
|
|
|
|
|
|
|
for i, item in component.items:
|
|
|
|
|
igTableNextRow(ImGuiTableRowFlags_None.int32, 0.0f)
|
|
|
|
|
|
|
|
|
|
if igTableSetColumnIndex(0):
|
|
|
|
|
igPushID_Int(i.int32)
|
|
|
|
|
let isSelected = component.selectedIndex == i
|
2025-10-09 12:14:38 +02:00
|
|
|
if igSelectable_Bool(item.lootId.cstring, isSelected, ImGuiSelectableFlags_SpanAllColumns.int32 or ImGuiSelectableFlags_AllowOverlap.int32, vec2(0, 0)):
|
2025-10-07 21:16:17 +02:00
|
|
|
component.selectedIndex = i
|
|
|
|
|
igPopID()
|
|
|
|
|
|
|
|
|
|
if igTableSetColumnIndex(1):
|
2025-10-09 12:14:38 +02:00
|
|
|
igText(item.agentId)
|
2025-10-07 21:16:17 +02:00
|
|
|
|
|
|
|
|
if igTableSetColumnIndex(2):
|
|
|
|
|
igText(item.host.cstring)
|
2025-10-09 12:14:38 +02:00
|
|
|
|
|
|
|
|
if igTableSetColumnIndex(3):
|
|
|
|
|
igText(item.path.extractFilename().replace("C_", "C:/").replace("_", "/"))
|
|
|
|
|
|
|
|
|
|
if igTableSetColumnIndex(4):
|
|
|
|
|
igText(item.timestamp.fromUnix().local().format("dd-MM-yyyy HH:mm:ss"))
|
2025-10-07 21:16:17 +02:00
|
|
|
|
2025-10-09 12:14:38 +02:00
|
|
|
if igTableSetColumnIndex(5):
|
|
|
|
|
igText($item.size)
|
|
|
|
|
|
2025-10-07 21:16:17 +02:00
|
|
|
igEndTable()
|
|
|
|
|
|
|
|
|
|
igEndChild()
|
|
|
|
|
igSameLine(0.0f, 0.0f)
|
|
|
|
|
|
|
|
|
|
# Right panel (file content)
|
|
|
|
|
if igBeginChild_Str("##Preview", vec2(0.0f, 0.0f), ImGui_ChildFlags_Borders.int32, ImGui_WindowFlags_None.int32):
|
2025-10-03 12:44:28 +02:00
|
|
|
|
2025-10-07 21:16:17 +02:00
|
|
|
if component.selectedIndex >= 0 and component.selectedIndex < component.items.len:
|
|
|
|
|
let item = component.items[component.selectedIndex]
|
|
|
|
|
|
2025-10-09 12:14:38 +02:00
|
|
|
igText(fmt("[{item.host}] "))
|
|
|
|
|
igSameLine(0.0f, 0.0f)
|
|
|
|
|
igText(item.path.extractFilename().replace("C_", "C:/").replace("_", "/"))
|
|
|
|
|
|
|
|
|
|
igSeparator()
|
|
|
|
|
|
|
|
|
|
igText(item.data)
|
2025-10-07 21:16:17 +02:00
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
igText("Select item to preview contents")
|
|
|
|
|
igEndChild()
|