Calibre portable: Do not allow calibre portable to run if it is placed in a location whose path is too long. Also hide the library location setup in the welcome wizard when running the portable build.

This commit is contained in:
Kovid Goyal 2012-02-25 12:19:00 +05:30
parent 9df6413df5
commit f8c70eccde
3 changed files with 19 additions and 6 deletions

View File

@ -53,7 +53,7 @@ void show_last_error(LPCTSTR preamble) {
NULL, NULL,
dw, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
&msg, (LPTSTR)&msg,
0, NULL ); 0, NULL );
show_detailed_error(preamble, msg, (int)dw); show_detailed_error(preamble, msg, (int)dw);
@ -136,7 +136,7 @@ void launch_calibre(LPCTSTR exe, LPCTSTR config_dir, LPCTSTR library_dir) {
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; LPTSTR app_dir, config_dir, exe, library_dir, too_long;
app_dir = get_app_dir(); app_dir = get_app_dir();
config_dir = (LPTSTR)calloc(BUFSIZE, sizeof(TCHAR)); config_dir = (LPTSTR)calloc(BUFSIZE, sizeof(TCHAR));
@ -147,7 +147,15 @@ 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);
if ( _tcscnlen(library_dir, BUFSIZE) <= 74 ) {
launch_calibre(exe, config_dir, library_dir); launch_calibre(exe, config_dir, library_dir);
} else {
too_long = (LPTSTR)calloc(BUFSIZE+300, sizeof(TCHAR));
_sntprintf_s(too_long, BUFSIZE+300, _TRUNCATE,
_T("Path to Calibre Portable (%s) too long. Must be less than 59 characters."), app_dir);
show_error(too_long);
}
free(app_dir); free(config_dir); free(exe); free(library_dir); free(app_dir); free(config_dir); free(exe); free(library_dir);

View File

@ -16,7 +16,8 @@ from PyQt4.Qt import (QWizard, QWizardPage, QPixmap, Qt, QAbstractListModel,
from calibre import __appname__, patheq from calibre import __appname__, patheq
from calibre.library.database2 import LibraryDatabase2 from calibre.library.database2 import LibraryDatabase2
from calibre.library.move import MoveLibrary from calibre.library.move import MoveLibrary
from calibre.constants import filesystem_encoding, iswindows, plugins from calibre.constants import (filesystem_encoding, iswindows, plugins,
isportable)
from calibre.gui2.wizard.send_email import smtp_prefs from calibre.gui2.wizard.send_email import smtp_prefs
from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI
from calibre.gui2.wizard.library_ui import Ui_WizardPage as LibraryUI from calibre.gui2.wizard.library_ui import Ui_WizardPage as LibraryUI
@ -769,6 +770,10 @@ class LibraryPage(QWizardPage, LibraryUI):
traceback.print_exc() traceback.print_exc()
lp = os.path.expanduser(u'~') lp = os.path.expanduser(u'~')
self.location.setText(lp) self.location.setText(lp)
# Hide the library location settings if we are a portable install
for x in ('location', 'button_change', 'libloc_label1',
'libloc_label2'):
getattr(self, x).setVisible(not isportable)
def isComplete(self): def isComplete(self):
try: try:

View File

@ -34,7 +34,7 @@
<widget class="QComboBox" name="language"/> <widget class="QComboBox" name="language"/>
</item> </item>
<item row="2" column="0" colspan="3"> <item row="2" column="0" colspan="3">
<widget class="QLabel" name="label"> <widget class="QLabel" name="libloc_label1">
<property name="text"> <property name="text">
<string>&lt;p&gt;Choose a location for your books. When you add books to calibre, they will be copied here. Use an &lt;b&gt;empty folder&lt;/b&gt; for a new calibre library:</string> <string>&lt;p&gt;Choose a location for your books. When you add books to calibre, they will be copied here. Use an &lt;b&gt;empty folder&lt;/b&gt; for a new calibre library:</string>
</property> </property>
@ -58,7 +58,7 @@
</widget> </widget>
</item> </item>
<item row="4" column="0" colspan="3"> <item row="4" column="0" colspan="3">
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="libloc_label2">
<property name="text"> <property name="text">
<string>If you have an existing calibre library, it will be copied to the new location. If a calibre library already exists at the new location, calibre will switch to using it.</string> <string>If you have an existing calibre library, it will be copied to the new location. If a calibre library already exists at the new location, calibre will switch to using it.</string>
</property> </property>