blob: f427b99331e0e3c710b0f04c99308e20a65a3ab4 [file] [log] [blame]
James Kuszmaulcf324122023-01-14 14:07:17 -08001// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <memory>
8#include <string>
9#include <thread>
10#include <vector>
11
12#include <wpi/condition_variable.h>
13#include <wpi/mutex.h>
14
15namespace glass {
16class Storage;
17} // namespace glass
18
19namespace pfd {
20class select_folder;
21} // namespace pfd
22
23class Downloader {
24 public:
25 explicit Downloader(glass::Storage& storage);
26 ~Downloader();
27
28 void Display();
29
30 private:
31 void DisplayConnect();
32 void DisplayDisconnectButton();
33 void DisplayRemoteDirSelector();
34 void DisplayLocalDirSelector();
35 size_t DisplayFiles();
36
37 void ThreadMain();
38
39 wpi::mutex m_mutex;
40 enum State {
41 kDisconnected,
42 kConnecting,
43 kConnected,
44 kDisconnecting,
45 kGetFiles,
46 kDownload,
47 kDownloadDone,
James Kuszmaulb13e13f2023-11-22 20:44:04 -080048 kDelete,
49 kDeleteDone,
James Kuszmaulcf324122023-01-14 14:07:17 -080050 kExit
51 } m_state = kDisconnected;
52 std::condition_variable m_cv;
53
54 std::string& m_serverTeam;
55 std::string& m_remoteDir;
56 std::string& m_username;
57 std::string m_password;
58
59 std::string& m_localDir;
60 std::unique_ptr<pfd::select_folder> m_localDirSelector;
61
62 bool& m_deleteAfter;
63
64 std::vector<std::string> m_dirList;
James Kuszmaulb13e13f2023-11-22 20:44:04 -080065 struct FileState {
66 FileState(std::string_view name, uint64_t size) : name{name}, size{size} {}
James Kuszmaulcf324122023-01-14 14:07:17 -080067
68 std::string name;
69 uint64_t size;
James Kuszmaulb13e13f2023-11-22 20:44:04 -080070 bool selected = true;
James Kuszmaulcf324122023-01-14 14:07:17 -080071 float complete = 0.0;
72 std::string status;
73 };
James Kuszmaulb13e13f2023-11-22 20:44:04 -080074 std::vector<FileState> m_fileList;
James Kuszmaulcf324122023-01-14 14:07:17 -080075
76 std::string m_error;
77
78 std::thread m_thread;
79};