Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to import KA Lite database during upgrade. #462

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 46 additions & 37 deletions windows/installer-source/KaliteSetupScript.iss
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,51 @@ begin
end;
end;

{ This will allow the user to import KA Lite database during upgrade. }
procedure SelectKaliteDatabase;
var
kaliterDir : String;
systemKaliteDir : String;
userDatabasePAth : String;
databasePAth : String;
systemKaliteDir : String;
userPath : String;
kaliteDb : String;
retCode: Integer;
begin
userPath := ExpandConstant('{%USERPROFILE}');
kaliterDir := ExpandConstant('{%KALITE_DIR}');
userDatabasePAth := ExpandConstant(systemKaliteDir + '\database');
systemKaliteDir := ExpandConstant(ExpandConstant('{%USERPROFILE}') + '\.kalite');
databasePAth := systemKaliteDir + 'database';
if(MsgBox('Would you like to import a KA Lite database?', mbConfirmation, MB_YESNO) = idYes) then
begin;
if BrowseForFolder('Please select the KA Lite database folder', userPath, False) then
begin
kaliteDb := userPath + '\data.sqlite';
if FileExists(kaliteDb) then
begin

if Not DirExists(kaliterDir) then
begin
kaliterDir := systemKaliteDir;
end
if not Exec(ExpandConstant('{cmd}'), '/C "xcopy "' + kaliteDb + '" "' + kaliterDir + '\database' +'\" /Y /S"', '', SW_HIDE, ewWaitUntilTerminated, retCode) then
begin
MsgBox('KA Lite Setup' #13#13 'Failed to import KA Lite database from this path ' + userPath, mbError, MB_OK);
end
end
else
begin
MsgBox('KA Lite Setup' #13#13 'Couldn`t find any database file at this path' + userPath, mbError, MB_OK);
end
end
end;
end;

procedure HandleUpgrade(targetPath : String);
var
prevVerStr : String;
userKaliteContent: String;
systemKaliteDir: String;
userPath : String;
contentPath : String;
contentDb : String;
retCode: Integer;
begin
prevVerStr := GetPreviousVersion();
Expand All @@ -267,8 +304,10 @@ begin
end
else
begin
{ This is where version-specific migration stuff should happen. }

SelectKaliteDatabase;

{ This is where version-specific migration stuff should happen. }
if CompareStr(prevVerStr, '0.13.99') < 0 then
begin
if CompareStr('{#TargetVersion}', '0.14.0') >= 0 then
Expand Down Expand Up @@ -298,37 +337,6 @@ begin
end;
end;
end;
userPath := ExpandConstant('{%USERPROFILE}')
contentPath := ExpandConstant('{%CONTENT_ROOT}')
systemKaliteDir := ExpandConstant(userPath + '\.kalite')
userKaliteContent := ExpandConstant(systemKaliteDir + '\content');
if Not DirExists(userKaliteContent) then
begin
if Not DirExists(contentPath) then
begin
MsgBox('KA Lite Setup is unable to locate the content folder of your previous installation in order to perform the upgrade to current version. Please select the .kalite/content/ folder on your computer and press the button OK to finish the upgrade process.', mbInformation, MB_OK);
if BrowseForFolder('Please select the .kalite/content/ folder', userPath, False) then
begin
RegWriteStringValue(
HKLM,
'System\CurrentControlSet\Control\Session Manager\Environment',
'CONTENT_ROOT',
userPath
);
contentDb := ExtractFilePath(userPath) + 'database\data.sqlite'
if FileExists(contentDb) then
begin
if(MsgBox('KA Lite found an existing database at your content folder,' #13
'Do you wish to import this database into KA Lite', mbConfirmation, MB_YESNO) = idYes) then
begin
Exec(ExpandConstant('{cmd}'), '/C "xcopy "' + ExtractFilePath(userPath) + 'database\*.sqlite' +'" "' + systemKaliteDir + '\database' +'\" /Y /S"', '', SW_SHOW, ewWaitUntilTerminated, retCode)
end
end
end;
end;

end;

{ forceCancel will be true if something went awry in DoGitMigrate... abort instead of trampling the user's data. }
if Not forceCancel then
begin
Expand All @@ -352,6 +360,7 @@ begin
{ Unclear what the logic here is. This is only executed if HandleUpgrade was not previously run. }
if Not isUpgrade then
HandleUpgrade(ExpandConstant('{app}'));

end;
end;

Expand Down