mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Calibre portable: Allow renaming of the 'Calibre Library' folder to something else
This commit is contained in:
parent
95b52a2059
commit
2a7a7cab4c
@ -442,7 +442,7 @@ class Win32Freeze(Command, WixMixIn):
|
|||||||
'/RELEASE',
|
'/RELEASE',
|
||||||
'/ENTRY:wWinMainCRTStartup',
|
'/ENTRY:wWinMainCRTStartup',
|
||||||
'/OUT:'+exe, self.embed_resources(exe),
|
'/OUT:'+exe, self.embed_resources(exe),
|
||||||
obj, 'User32.lib']
|
obj, 'User32.lib', 'Shlwapi.lib']
|
||||||
self.run_builder(cmd)
|
self.run_builder(cmd)
|
||||||
|
|
||||||
self.info('Creating portable installer')
|
self.info('Creating portable installer')
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <Shlwapi.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -134,6 +135,46 @@ void launch_calibre(LPCTSTR exe, LPCTSTR config_dir, LPCTSTR library_dir) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL is_dots(LPCTSTR name) {
|
||||||
|
return _tcscmp(name, _T(".")) == 0 || _tcscmp(name, _T("..")) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void find_calibre_library(LPTSTR library_dir) {
|
||||||
|
TCHAR base[BUFSIZE] = {0}, buf[BUFSIZE] = {0};
|
||||||
|
WIN32_FIND_DATA fdFile;
|
||||||
|
HANDLE hFind = NULL;
|
||||||
|
|
||||||
|
_sntprintf_s(buf, BUFSIZE, _TRUNCATE, _T("%s\\metadata.db"), base);
|
||||||
|
|
||||||
|
if (PathFileExists(buf)) return; // Calibre Library/metadata.db exists, we use it
|
||||||
|
|
||||||
|
_tcscpy(base, library_dir);
|
||||||
|
PathRemoveFileSpec(base);
|
||||||
|
|
||||||
|
_sntprintf_s(buf, BUFSIZE, _TRUNCATE, _T("%s\\*"), base);
|
||||||
|
|
||||||
|
// Look for some other folder that contains a metadata.db file inside the Calibre Portable folder
|
||||||
|
if((hFind = FindFirstFileEx(buf, FindExInfoStandard, &fdFile, FindExSearchLimitToDirectories, NULL, 0))
|
||||||
|
!= INVALID_HANDLE_VALUE) {
|
||||||
|
do {
|
||||||
|
if(is_dots(fdFile.cFileName)) continue;
|
||||||
|
|
||||||
|
if(fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||||
|
_sntprintf_s(buf, BUFSIZE, _TRUNCATE, _T("%s\\%s\\metadata.db"), base, fdFile.cFileName);
|
||||||
|
if (PathFileExists(buf)) {
|
||||||
|
// some dir/metadata.db exists, we use it as the library
|
||||||
|
PathRemoveFileSpec(buf);
|
||||||
|
_tcscpy(library_dir, buf);
|
||||||
|
FindClose(hFind);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while(FindNextFile(hFind, &fdFile));
|
||||||
|
FindClose(hFind);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
|
||||||
{
|
{
|
||||||
LPTSTR app_dir, config_dir, exe, library_dir, too_long;
|
LPTSTR app_dir, config_dir, exe, library_dir, too_long;
|
||||||
@ -147,6 +188,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
|
|||||||
_sntprintf_s(exe, BUFSIZE, _TRUNCATE, _T("%sCalibre\\calibre.exe"), app_dir);
|
_sntprintf_s(exe, BUFSIZE, _TRUNCATE, _T("%sCalibre\\calibre.exe"), app_dir);
|
||||||
_sntprintf_s(library_dir, BUFSIZE, _TRUNCATE, _T("%sCalibre Library"), app_dir);
|
_sntprintf_s(library_dir, BUFSIZE, _TRUNCATE, _T("%sCalibre Library"), app_dir);
|
||||||
|
|
||||||
|
find_calibre_library(library_dir);
|
||||||
|
|
||||||
if ( _tcscnlen(library_dir, BUFSIZE) <= 74 ) {
|
if ( _tcscnlen(library_dir, BUFSIZE) <= 74 ) {
|
||||||
launch_calibre(exe, config_dir, library_dir);
|
launch_calibre(exe, config_dir, library_dir);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user