Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added config entry for temporary directory #6

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,7 @@ $RECYCLE.BIN/
*.lnk
*.exe

# Cmake files
CMakeCache.txt
CmakeLists.txt
CMakeFiles
5 changes: 3 additions & 2 deletions OcapReplaySaver2/CmakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ add_library(OcapReplaySaver2 SHARED

include_directories(include)

target_link_libraries(OcapReplaySaver2 CURL::libcurl)
target_link_libraries(OcapReplaySaver2 ZLIB::ZLIB)
target_link_libraries(OcapReplaySaver2 ${CURL_LIBRARIES})
target_link_libraries(OcapReplaySaver2 ${ZLIB_LIBRARIES})
target_link_libraries(OcapReplaySaver2 stdc++fs)

IF (WIN32)
ELSE()
Expand Down
1 change: 1 addition & 0 deletions OcapReplaySaver2/OcapReplaySaver2.cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"httpRequestTimeout": 120,
"logAndTmpPrefix": "ocap-",
"logsDir": "./OCAPLOG",
"tempDir": "./OCAPTMP",
"newServerGameType": "TvT",
"newUrl": "http://127.0.0.1/api/v1/operations/add",
"newUrlRequestSecret": "pwd1234",
Expand Down
20 changes: 18 additions & 2 deletions OcapReplaySaver2/OcapReplaySaver2.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// by Zealot
// MIT licence https://opensource.org/licenses/MIT

#define CURRENT_VERSION "4.4.2.3"
#define CURRENT_VERSION "4.4.3.0"

#include <cstring>
#include <cstdio>
Expand All @@ -27,6 +27,7 @@
#include <cstdint>
#include <filesystem>
#include <optional>
#include <condition_variable>

#ifdef _WIN32
#include <Windows.h>
Expand Down Expand Up @@ -144,6 +145,7 @@ namespace {
int httpRequestTimeout{ 120 };
int traceLog{ 0 };
std::string logsDir{ "./OCAPLOG" };
std::string tempDir{ "./OCAPTMP" };
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indig0fox with that change it will use this folder by default.
Should i change it back to the old behaviour, so that i will use the default os temp folder until you configure a custom one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think keeping existing log behavior and default folder, and adding a default temp dir alongside it in the Arma root for storing backup .gz, is the most intuitive way forward. I would remove the os default temp folder usage entirely. With this, logs will always tie to recordings in the a3 root regardless of profile, user account, or install environment.

std::string logAndTmpPrefix{ "ocap-" };
// TODO: new names and comments, logs dir, change types accordingly, chenage default values
} config;
Expand Down Expand Up @@ -461,6 +463,20 @@ fs::path getAndCreateLogDirectory() {
return res;
}

fs::path getAndCreateTempDirectory() {
fs::path res = config.tempDir;
//res += "/";
//res += "OCAPLOG";
res.make_preferred();
try {
fs::create_directories(res);
}
catch (const std::exception& ex) {
LOG(WARNING) << "Error create directories: " << ex.what();
}
return res;
}

std::string uniqueFileName() {
std::srand(std::time(nullptr));
std::string res(5, '\0');
Expand All @@ -473,7 +489,7 @@ std::string uniqueFileName() {
}

pair<std::string, std::optional<std::string> > saveCurrentReplayToTempFile() {
fs::path temp_fname = fs::temp_directory_path();
fs::path temp_fname = getAndCreateTempDirectory();
temp_fname += "/";

temp_fname += config.logAndTmpPrefix;
Expand Down
17 changes: 17 additions & 0 deletions build-docker-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
docker run --rm --platform linux/amd64 -it -v .:/build ubuntu:20.04 bash -c '\
apt-get update &&\
apt-get install -y build-essential cmake g++ libcurl4-openssl-dev zlib1g-dev &&\
cd /build/OcapReplaySaver2 &&\
cmake . &&\
make &&\
mkdir -p /build/build/ubuntu_20.04/
cp OcapReplaySaver2_x64.so /build/build/ubuntu_20.04/'

docker run --rm --platform linux/amd64 -it -v .:/build ubuntu:22.04 bash -c '\
apt-get update &&\
apt-get install -y build-essential cmake g++ libcurl4-openssl-dev zlib1g-dev &&\
cd /build/OcapReplaySaver2 &&\
cmake . &&\
make &&\
mkdir -p /build/build/ubuntu_22.04/
cp OcapReplaySaver2_x64.so /build/build/ubuntu_22.04/'