Skip to content

Commit

Permalink
Add support for "Build As..." operation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joyfullservice committed Jul 8, 2023
1 parent 810a2bc commit 6eeebfa
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 10 deletions.
74 changes: 74 additions & 0 deletions Version Control.accda.src/modules/clsVersionControl.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 16 additions & 10 deletions Version Control.accda.src/modules/modImportExport.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6eeebfa

Please sign in to comment.