Skip to content

Commit

Permalink
Fixed some WinUsb issues
Browse files Browse the repository at this point in the history
Using find_path to locate winusb.h sometimes found the header in another
SDK. Adding that to the include path caused problems due to inter-header
dependencies. The header is also missing from some SDKs, including the
8.1 SDK in VS2017, even though they have the import library.

We now bundle our own winusb definitions, but use any winusb.lib found.
  • Loading branch information
simonowen committed Apr 19, 2020
1 parent e91a195 commit 2ae9cfe
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
13 changes: 8 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.3)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
cmake_policy(SET CMP0091 NEW) # Allow MSVC_RUNTIME_LIBRARY override
endif()

project(samdisk)
set(PROJECT_TITLE SAMdisk)

Expand Down Expand Up @@ -112,12 +116,11 @@ if (LIBLZMA_FOUND)
set(HAVE_LZMA 1)
endif()

find_library(WINUSB_LIBRARY NAMES winusb)
find_path(WINUSB_INCLUDE_DIR NAMES winusb.h)
if (WINUSB_LIBRARY AND WINUSB_INCLUDE_DIR)
message(STATUS "Found WinUSB: ${LIBUSB1_LIBRARY}")
target_include_directories(${PROJECT_NAME} PRIVATE ${WINUSB_INCLUDE_DIR})
find_library(WINUSB_LIBRARY NAMES winusb ENV LD_LIBRARY_PATH)
if (WINUSB_LIBRARY)
message(STATUS "Found winusb: ${WINUSB_LIBRARY}")
target_link_libraries(${PROJECT_NAME} ${WINUSB_LIBRARY})
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/DELAYLOAD:winusb.dll")
set(HAVE_WINUSB 1)
endif()

Expand Down
2 changes: 1 addition & 1 deletion License.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2002-2018 Simon Owen, http://simonowen.com
Copyright (c) 2002-2020 Simon Owen, https://simonowen.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion include/KF_WinUsb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#ifdef HAVE_WINUSB

#include <winusb.h>
#include "winusb_defs.h" // just the definitions we need
#include "KryoFlux.h"

class KF_WinUsb final : public KryoFlux
Expand Down
8 changes: 8 additions & 0 deletions src/KF_WinUsb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
#include <codecvt>
#include <setupapi.h>

#ifndef INITGUID
#define INITGUID
#include <guiddef.h>
#undef INITGUID
#else
#include <guiddef.h>
#endif

DEFINE_GUID(GUID_KRYOFLUX, 0x9E09C9CD, 0x5068, 0x4b31, 0x82, 0x89, 0xE3, 0x63, 0xE4, 0xE0, 0x62, 0xAC);

/*static*/ std::string KF_WinUsb::GetDevicePath()
Expand Down
Binary file removed src/RCa06704
Binary file not shown.
2 changes: 1 addition & 1 deletion src/SAMdisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int Usage()
<< " -b, --base=N override lowest sector number (default=" << fmtMGT.base << ")\n"
<< " -0, --head[0|1]=N override head 0 or 1 value\n"
<< "\n"
<< "See " << colour::CYAN << "http://simonowen.com/samdisk/" << colour::none << " for further details.\n";
<< "See " << colour::CYAN << "https://simonowen.com/samdisk/" << colour::none << " for further details.\n";

exit(1);
}
Expand Down

0 comments on commit 2ae9cfe

Please sign in to comment.