Skip to content

Commit 097651d

Browse files
committed
fix crash bug in windows and add new filesystem
1 parent acb9dc5 commit 097651d

File tree

8 files changed

+57
-74
lines changed

8 files changed

+57
-74
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "3rdparty/filesystem"]
2+
path = 3rdparty/filesystem
3+
url = https://github.com/gulrak/filesystem.git

3rdparty/filesystem

Submodule filesystem added at 3605e86

CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
cmake_minimum_required(VERSION 2.9)
22
project(qmc-decoder)
33

4-
set(CMAKE_FIND_ROOT_PATH "${PROJECT_SOURCE_DIR}/usr")
54
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
6-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pipe -std=c++11")
7-
if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
8-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
5+
6+
if (MSVC)
7+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
8+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Od")
9+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
10+
else(MSVC)
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pipe -std=c++11")
12+
endif()
13+
14+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
15+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -pthread -static-libgcc -static-libstdc++")
916
endif()
10-
find_package(Boost 1.56 REQUIRED COMPONENTS
11-
filesystem)
12-
include_directories(${Boost_INCLUDE_DIRS})
17+
18+
include_directories(3rdparty/filesystem/include)
1319
aux_source_directory(src SRC)
1420
add_executable(decoder ${SRC})
15-
target_link_libraries(decoder Boost::filesystem)
1621

boost.sh

Lines changed: 0 additions & 36 deletions
This file was deleted.

decoder.command

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
cd $(dirname $0)
3+
if [ -f decoder ]; then
4+
./decoder
5+
fi

mingw-w64-x86_64.cmake

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/decoder.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
/*
2+
* Author: mayusheng - [email protected]
3+
* Last modified: 2020-06-29 10:56
4+
* Filename: decoder.cpp
5+
*
6+
* Description: qmc file auto decode
7+
*
8+
*
9+
*/
110
#include <algorithm>
2-
#include <boost/filesystem.hpp>
311
#include <iostream>
412
#include <memory>
513
#include <regex>
614
#include <vector>
715

816
#include "seed.hpp"
917

10-
namespace fs = boost::filesystem;
18+
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
19+
#if __has_include(<filesystem>)
20+
#define GHC_USE_STD_FS
21+
#include <filesystem>
22+
namespace fs = std::filesystem;
23+
#endif
24+
#endif
25+
#ifndef GHC_USE_STD_FS
26+
#include <ghc/filesystem.hpp>
27+
namespace fs = ghc::filesystem;
28+
#endif
1129

1230
namespace {
1331
void close_file(std::FILE* fp) { std::fclose(fp); }
@@ -31,9 +49,9 @@ smartFilePtr openFile(const std::string& aPath, openMode aOpenMode) {
3149
int newSize = MultiByteToWideChar(CP_UTF8, 0, aPath.c_str(), aPath.length(),
3250
const_cast<wchar_t*>(aPath_w.c_str()),
3351
aPath_w.size());
34-
filePathW.resize(newSize);
35-
std::FILE* fp =
36-
_wfopen(aPath_w.c_str(), aOpenMode == openMode::read ? L"rb" : L"wb");
52+
aPath_w.resize(newSize);
53+
std::FILE* fp = NULL;
54+
_wfopen_s(&fp, aPath_w.c_str(), aOpenMode == openMode::read ? L"rb" : L"wb");
3755
#endif
3856
return smartFilePtr(fp, &close_file);
3957
}
@@ -114,7 +132,7 @@ int main(int argc, char** argv) {
114132
}
115133

116134
if ((fs::status(fs::path(".")).permissions() & fs::perms::owner_write) ==
117-
fs::perms::no_perms) {
135+
fs::perms::none) {
118136
std::cerr << "please check if you have the write permissions on this dir."
119137
<< std::endl;
120138
return -1;
@@ -125,7 +143,7 @@ int main(int argc, char** argv) {
125143
auto file_path = p.path().string();
126144

127145
if ((fs::status(p).permissions() & fs::perms::owner_read) !=
128-
fs::perms::no_perms &&
146+
fs::perms::none &&
129147
fs::is_regular_file(p) && regex_match(file_path, qmc_regex)) {
130148
qmc_paths.emplace_back(std::move(file_path));
131149
}

src/seed.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1+
/*
2+
* Author: mayusheng - [email protected]
3+
* Last modified: 2020-06-29 10:57
4+
* Filename: seed.hpp
5+
*
6+
* Description:
7+
*
8+
*
9+
*/
110
#ifndef SEED_H
211
#define SEED_H
312

413
#include <array>
14+
#include <cstdio>
515

616
namespace qmc_decoder {
717
class seed {

0 commit comments

Comments
 (0)