1#include "cmdline_tools.h"
2#include <cgv/utils/file.h>
4#include <cgv/utils/progression.h>
8#define popen(...) _popen(__VA_ARGS__);
9#define pclose(...) _pclose(__VA_ARGS__);
15 bool expand_archive(
const std::string& file_path,
const std::string& destination_path)
19 command =
"PowerShell -Command \"Expand-Archive -Path '";
20 command += file_path +
"' -DestinationPath '" + destination_path +
"'\"";
24 command += file_path +
"' -d '" + destination_path +
"'";
25 command = cgv::utils::file::clean_path(command);
27 int result = system(command.c_str());
31 bool compress_archive(
const std::string& file_filter_path,
const std::string& archive_path)
35 command =
"PowerShell -Command \"Compress-Archive -Path '";
36 command += file_filter_path +
"' -DestinationPath '" + archive_path +
"'\"";
39 command += archive_path +
"' '" + file_filter_path +
"'";
41 int result = system(command.c_str());
46 std::string query_system_output(std::string cmd,
bool cerr)
50 const int max_buffer = 256;
51 char buffer[max_buffer];
55 stream = popen(cmd.c_str(),
"r");
59 if (fgets(buffer, max_buffer, stream) != NULL) data.append(buffer);
64 size_t read_system_output(std::string cmd, uint8_t* buffer,
size_t buffer_size,
const char* progression_text,
bool use_cerr,
void (*on_progress_update)(
int,
void*),
void* user_data,
size_t block_size,
bool cycle_till_eof)
67 if (progression_text != 0)
73 const char* mode =
"rb";
75 const char* mode =
"r";
77 fp = popen(cmd.c_str(), mode);
78 size_t nr_bytes_read = 0;
81 while ((nr_bytes_read < buffer_size || cycle_till_eof) && !feof(fp)) {
82 size_t nr_bytes = block_size;
84 nr_bytes = std::min(nr_bytes, buffer_size - nr_bytes_read);
85 size_t offset = nr_bytes_read % buffer_size;
86 size_t nr_read = fread(buffer + offset, 1, nr_bytes, fp);
89 if (on_progress_update)
90 on_progress_update(++block_cnt, user_data);
91 nr_bytes_read += nr_read;
92 if (nr_read < nr_bytes)
99 FILE* open_system_input(
const std::string& cmd,
bool in_binary_mode)
102 const char* mode = in_binary_mode ?
"wb" :
"w";
104 const char* mode =
"w";
106 return popen(cmd.c_str(), mode);
108 FILE* open_system_output(
const std::string& cmd,
bool in_binary_mode)
111 const char* mode = in_binary_mode ?
"rb" :
"r";
113 const char* mode =
"r";
115 return popen(cmd.c_str(), mode);
117 int close_system_input(FILE* fp)
unsigned int replace(std::string &s, char c1, char c2)
replace char c1 with c2 in the given string _s and return number of replacements
Helper functions to process strings.
progression provides a simple possibility to show progression of process in console.
void step()
next iteration