From 6eeebfa0b79c3c3be0fdd3a6b0c5af0497fb70ee Mon Sep 17 00:00:00 2001 From: joyfullservice Date: Sat, 8 Jul 2023 17:31:41 -0500 Subject: [PATCH] Add support for "Build As..." operation This allows a user to build the current database as a different file name to to a different location. If no database is open, the user is prompted to select a source files folder. #410 --- .../modules/clsVersionControl.cls | 74 +++++++++++++++++++ .../modules/modImportExport.bas | 26 ++++--- 2 files changed, 90 insertions(+), 10 deletions(-) diff --git a/Version Control.accda.src/modules/clsVersionControl.cls b/Version Control.accda.src/modules/clsVersionControl.cls index af8125ce..19dba8c3 100644 --- a/Version Control.accda.src/modules/clsVersionControl.cls +++ b/Version Control.accda.src/modules/clsVersionControl.cls @@ -152,6 +152,80 @@ Public Sub MergeBuild() End Sub +'--------------------------------------------------------------------------------------- +' Procedure : BuildAs +' Author : Adam Waller +' Date : 7/8/2023 +' Purpose : Build the source files to a new file name or location. +' : If source files are identified for the currently open database, it will +' : build from those files. Otherwise it will ask the use to select a folder +' : with source files. +'--------------------------------------------------------------------------------------- +' +Public Sub BuildAs() + + Dim strNewDbPath As String + Dim strSourceFolder As String + + ' See if we can find source files for the currently open database. + If DatabaseFileOpen Then + If FolderHasVcsOptionsFile(Options.GetExportFolder) Then + ' Get the source folder location. + strSourceFolder = Options.GetExportFolder + End If + End If + + ' If we aren't doing the current database, then prompt user to find a folder + ' with source files to use for the build. + If strSourceFolder = vbNullString Then + + ' Show a folder picker to select the file with source code. + With Application.FileDialog(msoFileDialogFolderPicker) + .AllowMultiSelect = False + .ButtonName = "Select Source Files Folder" + .Title = "Select Source Folder" + .Show + If .SelectedItems.Count > 0 Then + ' Selected a folder + If FolderHasVcsOptionsFile(.SelectedItems(1)) Then + ' Has source files + strSourceFolder = .SelectedItems(1) & PathSep + Else + MsgBox2 "Source files not found", "Required source files were not found in this folder.", _ + "You selected: " & .SelectedItems(1), vbExclamation + Exit Sub + End If + Else + ' Canceled dialog + Exit Sub + End If + End With + End If + + ' At this point, we should have identified the source files folder. + ' Now, we need to get the desired new database file name. + With Application.FileDialog(msoFileDialogSaveAs) + .AllowMultiSelect = False + .ButtonName = "Build Here" + .Title = "Build New Database File" + If DatabaseFileOpen Then + .InitialFileName = CurrentProject.FullName + Else + .InitialFileName = GetOriginalDbFullPathFromSource(strSourceFolder) + End If + .Show + ' Return path to new file + If .SelectedItems.Count > 0 Then strNewDbPath = .SelectedItems(1) + End With + + ' Proceed with build if we have the new path. + If Len(strNewDbPath) Then + modImportExport.Build strSourceFolder, True, , strNewDbPath + End If + +End Sub + + '--------------------------------------------------------------------------------------- ' Procedure : MergeAllSource ' Author : Adam Waller diff --git a/Version Control.accda.src/modules/modImportExport.bas b/Version Control.accda.src/modules/modImportExport.bas index f4e2aa4f..7f2903d1 100644 --- a/Version Control.accda.src/modules/modImportExport.bas +++ b/Version Control.accda.src/modules/modImportExport.bas @@ -584,7 +584,8 @@ End Sub ' Purpose : Build the project from source files. '--------------------------------------------------------------------------------------- ' -Public Sub Build(strSourceFolder As String, blnFullBuild As Boolean, Optional intFilter As eContainerFilter = ecfAllObjects) +Public Sub Build(strSourceFolder As String, blnFullBuild As Boolean, _ + Optional intFilter As eContainerFilter = ecfAllObjects, Optional strAlternatePath As String) Dim strPath As String Dim strBackup As String @@ -646,12 +647,15 @@ Public Sub Build(strSourceFolder As String, blnFullBuild As Boolean, Optional in Set Options = Nothing Options.LoadOptionsFromFile StripSlash(strSourceFolder) & PathSep & "vcs-options.json" + ' Override the export folder when exporting to an alternate path. + If Len(strAlternatePath) Then Options.ExportFolder = strSourceFolder ' Build original file name for database If blnFullBuild Then - strPath = GetOriginalDbFullPathFromSource(strSourceFolder) + ' Use alternate path if provided, otherwise extract the original database path from the source files. + strPath = Nz2(strAlternatePath, GetOriginalDbFullPathFromSource(strSourceFolder)) If strPath = vbNullString Then - MsgBox2 "Unable to determine database file name", "Required source files were not found or could not be decrypted:", strSourceFolder, vbExclamation + MsgBox2 "Unable to determine database file name", "Required source files were not found or could not be parsed:", strSourceFolder, vbExclamation GoTo CleanUp End If Else @@ -926,14 +930,16 @@ CleanUp: DoEvents End If - ' Save index file (After build complete) - If blnFullBuild Then - ' NOTE: Add a couple seconds since some items may still be in the process of saving. - VCSIndex.FullBuildDate = DateAdd("s", 2, Now) - Else - VCSIndex.MergeBuildDate = DateAdd("s", 2, Now) + ' Save index file after build is complete, or discard index for "Build As..." + If strAlternatePath = vbNullString Then + If blnFullBuild Then + ' NOTE: Add a couple seconds since some items may still be in the process of saving. + VCSIndex.FullBuildDate = DateAdd("s", 2, Now) + Else + VCSIndex.MergeBuildDate = DateAdd("s", 2, Now) + End If + VCSIndex.Save strSourceFolder End If - VCSIndex.Save strSourceFolder Set VCSIndex = Nothing ' Show MessageBox if not using GUI for build.