Skip to content

Commit

Permalink
fix crash bug in windows and add new filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
Presburger committed Jun 29, 2020
1 parent acb9dc5 commit 097651d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "3rdparty/filesystem"]
path = 3rdparty/filesystem
url = https://github.com/gulrak/filesystem.git
1 change: 1 addition & 0 deletions 3rdparty/filesystem
Submodule filesystem added at 3605e8
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
cmake_minimum_required(VERSION 2.9)
project(qmc-decoder)

set(CMAKE_FIND_ROOT_PATH "${PROJECT_SOURCE_DIR}/usr")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pipe -std=c++11")
if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Android" AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")

if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Od")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
else(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pipe -std=c++11")
endif()

if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -pthread -static-libgcc -static-libstdc++")
endif()
find_package(Boost 1.56 REQUIRED COMPONENTS
filesystem)
include_directories(${Boost_INCLUDE_DIRS})

include_directories(3rdparty/filesystem/include)
aux_source_directory(src SRC)
add_executable(decoder ${SRC})
target_link_libraries(decoder Boost::filesystem)

36 changes: 0 additions & 36 deletions boost.sh

This file was deleted.

5 changes: 5 additions & 0 deletions decoder.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
cd $(dirname $0)
if [ -f decoder ]; then
./decoder
fi
23 changes: 0 additions & 23 deletions mingw-w64-x86_64.cmake

This file was deleted.

32 changes: 25 additions & 7 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
/*
* Author: mayusheng - [email protected]
* Last modified: 2020-06-29 10:56
* Filename: decoder.cpp
*
* Description: qmc file auto decode
*
*
*/
#include <algorithm>
#include <boost/filesystem.hpp>
#include <iostream>
#include <memory>
#include <regex>
#include <vector>

#include "seed.hpp"

namespace fs = boost::filesystem;
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
#if __has_include(<filesystem>)
#define GHC_USE_STD_FS
#include <filesystem>
namespace fs = std::filesystem;
#endif
#endif
#ifndef GHC_USE_STD_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
#endif

namespace {
void close_file(std::FILE* fp) { std::fclose(fp); }
Expand All @@ -31,9 +49,9 @@ smartFilePtr openFile(const std::string& aPath, openMode aOpenMode) {
int newSize = MultiByteToWideChar(CP_UTF8, 0, aPath.c_str(), aPath.length(),
const_cast<wchar_t*>(aPath_w.c_str()),
aPath_w.size());
filePathW.resize(newSize);
std::FILE* fp =
_wfopen(aPath_w.c_str(), aOpenMode == openMode::read ? L"rb" : L"wb");
aPath_w.resize(newSize);
std::FILE* fp = NULL;
_wfopen_s(&fp, aPath_w.c_str(), aOpenMode == openMode::read ? L"rb" : L"wb");
#endif
return smartFilePtr(fp, &close_file);
}
Expand Down Expand Up @@ -114,7 +132,7 @@ int main(int argc, char** argv) {
}

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

if ((fs::status(p).permissions() & fs::perms::owner_read) !=
fs::perms::no_perms &&
fs::perms::none &&
fs::is_regular_file(p) && regex_match(file_path, qmc_regex)) {
qmc_paths.emplace_back(std::move(file_path));
}
Expand Down
10 changes: 10 additions & 0 deletions src/seed.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/*
* Author: mayusheng - [email protected]
* Last modified: 2020-06-29 10:57
* Filename: seed.hpp
*
* Description:
*
*
*/
#ifndef SEED_H
#define SEED_H

#include <array>
#include <cstdio>

namespace qmc_decoder {
class seed {
Expand Down

0 comments on commit 097651d

Please sign in to comment.