1
0
mirror of https://github.com/chylex/Nextcloud-Desktop.git synced 2025-02-24 09:45:59 +01:00

Windows: Add Win32 stand-alone migration tool NCNavRemove

Removes all Explorer Navigation Pane entries for a given ApplicationName, specified in NavRemove.ini in the working directory.

Also compiles a DLL with the same behaviour that exports:
- RemoveNavigationPaneEntries

Both tool variants are Mutex-protected.

Statically linked, optimized for binary size, no Qt dependencies.

Signed-off-by: Michael Schuster <michael@schuster.ms>
This commit is contained in:
Michael Schuster 2020-09-05 06:58:48 +02:00
parent 68776fe319
commit f321cd8ae6
No known key found for this signature in database
GPG Key ID: 00819E3BF4177B28
15 changed files with 3864 additions and 0 deletions

View File

@ -59,3 +59,7 @@ add_subdirectory(NCToolsShared)
if(BUILD_WIN_MSI)
add_subdirectory(NCMsiHelper)
endif()
if(BUILD_WIN_TOOLS)
add_subdirectory(NCNavRemove)
endif()

View File

@ -0,0 +1,14 @@
project(NCNavRemove)
set(MUTEX_NAME "NCNavRemove")
configure_file(NavRemoveConstants.h.in ${CMAKE_CURRENT_BINARY_DIR}/NavRemoveConstants.h)
configure_file(NavRemove.ini.in ${CMAKE_CURRENT_BINARY_DIR}/NavRemove.ini)
configure_file(version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
add_subdirectory(dll)
add_subdirectory(exe)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/NavRemove.ini
DESTINATION tools/NCNavRemove/
)

View File

@ -0,0 +1,78 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "NCTools.h"
#include "3rdparty/SimpleIni.h"
#include "NavRemoveConstants.h"
#include "ConfigIni.h"
ConfigIni::ConfigIni()
{
}
bool ConfigIni::load()
{
std::wstring filename;
DWORD bufferLen = GetCurrentDirectory(0, nullptr);
TCHAR *pszBuffer = nullptr;
if (bufferLen == 0) {
return false;
}
pszBuffer = new TCHAR[bufferLen];
if (!pszBuffer) {
return false;
}
if (GetCurrentDirectory(bufferLen, pszBuffer) != 0) {
filename = pszBuffer;
}
delete [] pszBuffer;
if (filename.empty()) {
return false;
}
filename.append(L"\\");
filename.append(INI_NAME);
CSimpleIni ini;
const wchar_t iniSection[] = CFG_KEY;
const wchar_t iniKey[] = CFG_VAR_APPNAME;
auto rc = ini.LoadFile(filename.data());
if (rc != SI_OK) {
return false;
}
auto pv = ini.GetValue(iniSection, iniKey);
bool success = false;
if (pv) {
_appName = pv;
success = !_appName.empty();
}
ini.Reset();
return success;
}
const std::wstring ConfigIni::getAppName() const
{
return _appName;
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once
#include "NCTools.h"
class ConfigIni
{
public:
ConfigIni();
bool load();
const std::wstring getAppName() const;
private:
std::wstring _appName;
};

View File

@ -0,0 +1,2 @@
[NavRemove]
ApplicationName=@APPLICATION_NAME@

View File

@ -0,0 +1,9 @@
#pragma once
#define MUTEX_NAME L"@MUTEX_NAME@"
#define TOOL_NAME L"NCNavRemove (@BITNESS@-bit)"
#define TOOL_DESCRIPTION L"Removes all Explorer Navigation Pane entries for a given ApplicationName."
#define INI_NAME L"NavRemove.ini"
#define CFG_KEY L"NavRemove"
#define CFG_VAR_APPNAME L"ApplicationName"

View File

@ -0,0 +1,25 @@
add_definitions(-D_NAVREMOVE_EXPORTS)
add_definitions(-D_USRDLL)
add_definitions(-D_WINDLL)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}/../
)
set(TARGET_NAME libNavRemove${BITNESS})
add_library(${TARGET_NAME} MODULE
dllmain.cpp
NavRemove.cpp
exports.def
../ConfigIni.cpp
${CMAKE_CURRENT_BINARY_DIR}/../version.rc
)
target_link_libraries(${TARGET_NAME}
NCToolsShared
)
install(TARGETS ${TARGET_NAME}
DESTINATION tools/NCNavRemove/dll/
)

View File

@ -0,0 +1,40 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "NCTools.h"
#include "utility.h"
#include "NavRemove.h"
#include "../ConfigIni.h"
using namespace NCTools;
extern bool g_alreadyRunning;
HRESULT NAVREMOVE_API RemoveNavigationPaneEntries()
{
if (g_alreadyRunning) {
return S_OK;
}
// Config
ConfigIni ini;
if (!ini.load()) {
return HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
}
Utility::removeNavigationPaneEntries(ini.getAppName());
return S_OK;
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#pragma once
#include "NCTools.h"
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the _NAVREMOVE_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// NAVREMOVE_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef _NAVREMOVE_EXPORTS
#define NAVREMOVE_API __declspec(dllexport)
#else
#define NAVREMOVE_API __declspec(dllimport)
#endif
NAVREMOVE_API HRESULT RemoveNavigationPaneEntries();

View File

@ -0,0 +1,42 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "NCTools.h"
#include "SimpleMutex.h"
#include "NavRemoveConstants.h"
SimpleMutex g_mutex;
bool g_alreadyRunning = false;
extern "C" BOOL WINAPI DllMain(
__in HINSTANCE hInst,
__in ULONG ulReason,
__in LPVOID
)
{
switch(ulReason)
{
case DLL_PROCESS_ATTACH:
// Mutex
g_alreadyRunning = !g_mutex.create(std::wstring(MUTEX_NAME));
break;
case DLL_PROCESS_DETACH:
// Release mutex
g_mutex.release();
break;
}
return TRUE;
}

View File

@ -0,0 +1,2 @@
EXPORTS
RemoveNavigationPaneEntries

View File

@ -0,0 +1,19 @@
set(TARGET_NAME NavRemove${BITNESS})
include_directories(
${CMAKE_CURRENT_BINARY_DIR}/../
)
add_executable(${TARGET_NAME} WIN32
main.cpp
../ConfigIni.cpp
${CMAKE_CURRENT_BINARY_DIR}/../version.rc
)
target_link_libraries(${TARGET_NAME}
NCToolsShared
)
install(TARGETS ${TARGET_NAME}
DESTINATION tools/NCNavRemove/exe/
)

View File

@ -0,0 +1,53 @@
/*
* Copyright (C) by Michael Schuster <michael.schuster@nextcloud.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "NCTools.h"
#include "utility.h"
#include "SimpleMutex.h"
#include "NavRemoveConstants.h"
#include "../ConfigIni.h"
using namespace NCTools;
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hInstance);
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
// Mutex
SimpleMutex mutex;
if (!mutex.create(std::wstring(MUTEX_NAME))) {
return 0;
}
// Config
ConfigIni ini;
if (!ini.load()) {
return 1;
}
Utility::removeNavigationPaneEntries(ini.getAppName());
// Release mutex
mutex.release();
return 0;
}

View File

@ -0,0 +1,40 @@
#include "winresrc.h"
#include "NavRemoveConstants.h"
#define VER_FILEVERSION @MIRALL_VERSION_MAJOR@,@MIRALL_VERSION_MINOR@,@MIRALL_VERSION_PATCH@,@MIRALL_VERSION_BUILD@
#define VER_FILEVERSION_STR "@MIRALL_VERSION_MAJOR@.@MIRALL_VERSION_MINOR@.@MIRALL_VERSION_PATCH@.@MIRALL_VERSION_BUILD@\0"
#define VER_PRODUCTVERSION @MIRALL_VERSION_MAJOR@,@MIRALL_VERSION_MINOR@,@MIRALL_VERSION_PATCH@,@MIRALL_VERSION_BUILD@
#define VER_PRODUCTVERSION_STR "@MIRALL_VERSION_MAJOR@.@MIRALL_VERSION_MINOR@.@MIRALL_VERSION_PATCH@.@MIRALL_VERSION_BUILD@\0"
#define VER_PRODUCTNAME_STR TOOL_NAME
#define VER_COMPANYNAME_STR "@APPLICATION_VENDOR@"
#define VER_COPYRIGHT_STR "(c) @MIRALL_VERSION_YEAR@"
#define VER_PRODUCTDESC_STR TOOL_DESCRIPTION
VS_VERSION_INFO VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
FILEOS VOS__WINDOWS32
FILETYPE VFT_APP
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "080904b0"
BEGIN
VALUE "CompanyName", VER_COMPANYNAME_STR
VALUE "LegalCopyright", VER_COPYRIGHT_STR
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "Comment", VER_PRODUCTNAME_STR
VALUE "FileDescription", VER_PRODUCTDESC_STR
VALUE "ProductName", VER_PRODUCTNAME_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x809, 1200
END
END

File diff suppressed because it is too large Load Diff