James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1 | // 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 | |
| 15 | namespace glass { |
| 16 | class Storage; |
| 17 | } // namespace glass |
| 18 | |
| 19 | namespace pfd { |
| 20 | class select_folder; |
| 21 | } // namespace pfd |
| 22 | |
| 23 | class 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 48 | kDelete, |
| 49 | kDeleteDone, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 50 | 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 Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 65 | struct FileState { |
| 66 | FileState(std::string_view name, uint64_t size) : name{name}, size{size} {} |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 67 | |
| 68 | std::string name; |
| 69 | uint64_t size; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 70 | bool selected = true; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 71 | float complete = 0.0; |
| 72 | std::string status; |
| 73 | }; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 74 | std::vector<FileState> m_fileList; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 75 | |
| 76 | std::string m_error; |
| 77 | |
| 78 | std::thread m_thread; |
| 79 | }; |