Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from wiggleforlife/2.1-release
Browse files Browse the repository at this point in the history
v0.2.1
  • Loading branch information
wiggleforlife authored Mar 5, 2022
2 parents 46a8e74 + 4456573 commit 6abc9d1
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 173 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.16)
project(vatsim-mgr)
project(vatsim-manager)

set(CMAKE_CXX_STANDARD 14)

add_executable(vatsim-mgr main.cpp utils.cpp utils.h)
add_executable(vatsim-manager main.cpp utils.cpp utils.h download.cpp download.h global.h)

find_package(PkgConfig)
pkg_check_modules(libcurl REQUIRED IMPORTED_TARGET libcurl>=7.68.0)
target_link_libraries(vatsim-mgr PUBLIC PkgConfig::libcurl)
target_link_libraries(vatsim-manager PUBLIC PkgConfig::libcurl)
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
# vatsim-mgr
# vatsim-manager
### *A VATSIM client install manager for Linux*
![License](https://img.shields.io/github/license/wiggleforlife/vatsim-mgr?style=for-the-badge)
![Current version](https://img.shields.io/github/v/release/wiggleforlife/vatsim-mgr?style=for-the-badge)
![Repo size](https://img.shields.io/github/repo-size/wiggleforlife/vatsim-mgr?style=for-the-badge)
![License](https://img.shields.io/github/license/wiggleforlife/vatsim-manager?style=for-the-badge)
![Repo size](https://img.shields.io/github/repo-size/wiggleforlife/vatsim-manager?style=for-the-badge)
![Current version](https://img.shields.io/aur/version/vatsim-manager?style=for-the-badge)
![AUR maintainers](https://img.shields.io/aur/maintainer/vatsim-manager?style=for-the-badge)

Created by Cian Ormond with no endorsements by VATSIM staff members. For more info, run `vatsim-mgr -l`.
Created by Cian Ormond with no endorsements by VATSIM staff members. For more info, run `vatsim-mgr -L`.

### Current feature list
* Install and uninstall clients

### Planned feature list
* Configure xPilot's AppConfig with user input
* Keep track of installed clients, versions and paths
* Disallow uninstalling absent clients
* Confirm before reinstalling present clients
* Manage `winetricks` and `wine` settings in a custom `WINEPREFIX` for ATC clients

### Included clients
* xPilot 2.0.0 beta
![xPilot version](https://img.shields.io/github/v/release/xpilot-project/xpilot?include_prereleases&label=xPilot&style=flat-square)
![Swift version](https://img.shields.io/github/v/release/swift-project/pilotclient?include_prereleases&label=Swift&style=flat-square)
<!--TODO use version from VERSIONS-->

### Dependencies
* libCURL >=7.68.0
* jsoncpp >=1.7.4
* PkgConfig >=0.29.1

### Packages
* [AUR](https://aur.archlinux.com/vatsim-manager) (WIP)
### Installation
* [vatsim-manager](https://aur.archlinux.org/packages/vatsim-manager) on the Arch User Repository
* Build from [source](https://github.com/wiggleforlife/vatsim-manager/tree/release)
* `git clone https://github.com/wiggleforlife/vatsim-manager.git`
* `git switch release`
* `mkdir build && cd build`
* `cmake ..`
* `make`
* `sudo` or `doas mv vatsim-mgr /usr/bin/`

### Contribution
* Fork this repository and checkout a branch with the name of the patch
* Create a draft pull request to `wiggleforlife/vatsim-manager/master` with the intended changes
* Make your changes
* Mark the pull request as completed
2 changes: 1 addition & 1 deletion VERSIONS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xpilot=2.0.0-beta.21
xpilot=2.0.0-beta.32
swift=0.12.2
138 changes: 138 additions & 0 deletions download.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include "download.h"
#include <vector>
#include <iostream>
#include <curl/curl.h>
#include <string>
#include <sstream>
#include <math.h>

size_t download::write_data(char *ptr, size_t size, size_t nmemb, void *userdata) {
std::ostringstream *stream = (std::ostringstream*)userdata;
size_t count = size * nmemb;
stream->write(ptr, count);
return count;
}

std::vector<std::string> download::downloadPilotVersions() {

std::cout << "Downloading program version numbers" << std::endl;

CURL* curl = curl_easy_init();
CURLcode res;
const char* url = "https://raw.githubusercontent.com/wiggleforlife/vatsim-mgr/master/VERSIONS";
std::ostringstream stream;

if (!curl) {
fprintf(stderr,"[-] Failed Initializing Curl\n");
exit(-1);
}

curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream);
res = curl_easy_perform(curl);

if (res != CURLE_OK) {
fprintf(stderr,"[-] Could Not Fetch Webpage\n[+] Error: %s\n",curl_easy_strerror(res));
std::cout << res << std::endl;
exit(-2);
}

curl_easy_cleanup(curl);
std::string line;
std::string versionsTemp = stream.str();
std::stringstream ss(versionsTemp);
std::vector<std::string> versions;

while(getline(ss, line, '\n')) {
line = line.substr(line.find("=") + 1, line.length());
versions.push_back(line);
}

return versions;
}

int download::downloadPilotClient(int program) {

std::string programVersion = download::downloadPilotVersions().at(program);
std::string programName;
std::string url;

switch(program) {
case 0:
programName = "xPilot";
url = "https://github.com/xpilot-project/xpilot/releases/download/v" + programVersion + "/xPilot-" +
programVersion + "-linux-x64-installer.run";
break;
case 1:
programName = "Swift";
url = "https://github.com/swift-project/pilotclient/releases/download/v" + programVersion + "/swiftinstal" +
"ler-linux-64-" + programVersion + ".run";
break;
}

std::cout << "Downloading " << programName << " " << programVersion << std::endl;

CURL* curl = curl_easy_init();
CURLcode res;

std::string outputName = "/tmp/vatsim-manager/" + programName + ".run";
FILE* output = fopen(outputName.c_str(), "wb");

if (!curl) {
fprintf(stderr,"[-] Failed Initializing Curl\n");
exit(-1);
}

curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, output);
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func);
res = curl_easy_perform(curl);

if (res != CURLE_OK) {
fprintf(stderr,"[-] Could Not Fetch Webpage\n[+] Error: %s\n",curl_easy_strerror(res));
std::cout << res << std::endl;
exit(-2);
}

curl_easy_cleanup(curl);
fclose(output);

return 0;
}

// https://stackoverflow.com/questions/1637587/c-libcurl-console-progress-bar
int download::progress_func(void* ptr, double TotalToDownload, double NowDownloaded, double TotalToUpload,
double NowUploaded)
{
// ensure that the file to be downloaded is not empty
// because that would cause a division by zero error later on
if (TotalToDownload <= 0.0) {
return 0;
}

// how wide you want the progress meter to be
int totaldotz=40;
double fractiondownloaded = NowDownloaded / TotalToDownload;
// part of the progressmeter that's already "full"
int dotz = (int) round(fractiondownloaded * totaldotz);

// create the "meter"
int ii=0;
printf("%3.0f%% [",fractiondownloaded*100);
// part that's full already
for ( ; ii < dotz;ii++) {
printf("=");
}
// remaining part (spaces)
for ( ; ii < totaldotz;ii++) {
printf(" ");
}
// and back to line begin - do not forget the fflush to avoid output buffering problems!
printf("]\r");
fflush(stdout);
// if you don't return 0, the transfer will be aborted - see the documentation
return 0;
}
18 changes: 18 additions & 0 deletions download.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <vector>
#include <string>

#ifndef VATSIM_MGR_DOWNLOAD_H
#define VATSIM_MGR_DOWNLOAD_H

#endif //VATSIM_MGR_DOWNLOAD_H


class download {
public:
static std::vector<std::string> downloadPilotVersions();
int downloadPilotClient(int program);
private:
static size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata);
static int progress_func(void* ptr, double TotalToDownload, double NowDownloaded, double TotalToUpload,
double NowUploaded);
};
9 changes: 9 additions & 0 deletions global.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef VATSIM_MANAGER_GLOBAL_H
#define VATSIM_MANAGER_GLOBAL_H

#endif //VATSIM_MANAGER_GLOBAL_H

class global {
public:
const char* version = "0.2.1";
};
Loading

0 comments on commit 6abc9d1

Please sign in to comment.