Skip to content

Commit

Permalink
Re-architect PDFKeeper.WindowsApplication into separate projects appl…
Browse files Browse the repository at this point in the history
…ying the Model-View-Presenter pattern with Services and created additional projects for code that resides outside of the pattern. Migrated from Package.Config to PackageReference for NuGet packages.

Signed-off-by: Robert F. Frasca <[email protected]>
  • Loading branch information
rffrasca committed May 22, 2022
1 parent 7e5379a commit 9eb6614
Show file tree
Hide file tree
Showing 287 changed files with 15,964 additions and 14,658 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
*.exe
*.suo
/src/packages
/src/PDFKeeper.WindowsApplication/bin
/src/PDFKeeper.WindowsApplication/obj
*.user
*.chm
bin
obj
.vs
/src/PDFKeeper.WindowsApplication/*.editorconfig
*.editorconfig
*.dll
48 changes: 48 additions & 0 deletions src/PDFKeeper.Common/AppFolderShortcuts.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'******************************************************************************
'* PDFKeeper -- Open Source PDF Document Management
'* Copyright (C) 2009-2022 Robert F. Frasca
'*
'* This file is part of PDFKeeper.
'*
'* PDFKeeper is free software: you can redistribute it and/or modify
'* it under the terms of the GNU General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'*
'* PDFKeeper is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with PDFKeeper. If not, see <http://www.gnu.org/licenses/>.
'******************************************************************************
Imports System.IO

Public NotInheritable Class AppFolderShortcuts
Private Shared ReadOnly shortcutName = String.Concat(
My.Application.Info.ProductName, " ", My.Resources.Upload, ".lnk")
Private Shared ReadOnly documentsTargetPath = Path.Combine(UserProfileFolders.Documents, shortcutName)
Private Shared ReadOnly downloadsTargetPath = Path.Combine(UserProfileFolders.Downloads, shortcutName)

''' <summary>
''' Creates the PDFKeeper application folder shortcuts.
''' </summary>
''' <param name="targetFolderPath">Shortcut target folder path</param>
Public Shared Sub Create(ByVal targetFolderPath As String)
Dim dir = New DirectoryInfo(targetFolderPath)
CreateShortcut(dir, documentsTargetPath)
CreateShortcut(dir, downloadsTargetPath)
End Sub

''' <summary>
''' Deletes the PDFKeeper application folder shortcuts.
''' </summary>
Public Shared Sub Delete()
Try
IO.File.Delete(documentsTargetPath)
IO.File.Delete(downloadsTargetPath)
Catch ex As IOException
End Try
End Sub
End Class
92 changes: 92 additions & 0 deletions src/PDFKeeper.Common/AppFolders.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
'******************************************************************************
'* PDFKeeper -- Open Source PDF Document Management
'* Copyright (C) 2009-2022 Robert F. Frasca
'*
'* This file is part of PDFKeeper.
'*
'* PDFKeeper is free software: you can redistribute it and/or modify
'* it under the terms of the GNU General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'*
'* PDFKeeper is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with PDFKeeper. If not, see <http://www.gnu.org/licenses/>.
'******************************************************************************
Imports System.IO

Public NotInheritable Class AppFolders
''' <summary>
''' Application folder name type.
''' </summary>
Public Enum AppFolder
DataTopLevel
Cache
Upload
UploadProfiles
UploadRejected
UploadStaging
Temp
End Enum

''' <summary>
''' Gets the application folder path name and creates it.
''' </summary>
''' <param name="folder">Folder name</param>
''' <returns>Path name</returns>
Public Shared Function GetPath(ByVal folder As AppFolder) As String
Dim dirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
My.Application.Info.CompanyName, My.Application.Info.ProductName)
If folder <> AppFolder.DataTopLevel And folder <> AppFolder.Temp Then
dirPath = Path.Combine(dirPath, folder.ToString)
ElseIf folder = AppFolder.Temp Then
dirPath = Path.Combine(Path.GetTempPath, My.Application.Info.ProductName)
End If
If Directory.Exists(dirPath) = False And folder = AppFolder.UploadProfiles Then
UpgradeUploadProfiles(dirPath)
End If
Directory.CreateDirectory(dirPath)
If folder = AppFolder.Upload Then
AppFolderShortcuts.Create(dirPath)
End If
Return dirPath
End Function

''' <summary>
''' Empties an application data folder.
'''
''' For any file that cannot be deleted, its extension will be changed to "delete" so that it can be deleted during
''' the next run.
''' </summary>
''' <param name="folder">Folder name</param>
Public Shared Sub Empty(ByVal folder As AppFolder)
For Each item In Directory.GetFiles(GetPath(folder), "*.*")
Try
File.Delete(item)
Catch ex As IOException
End Try
If File.Exists(item) Then
File.Move(item, Path.ChangeExtension(item, "delete"))
End If
Next
End Sub

Private Shared Sub UpgradeUploadProfiles(ByVal dir As String)
Dim uploadConfigPath = Path.Combine(Directory.GetParent(dir).FullName, "UploadConfig")
If Directory.Exists(uploadConfigPath) Then
My.Computer.FileSystem.CopyDirectory(uploadConfigPath, dir)
For Each profile In Directory.GetFiles(dir, "*.xml", SearchOption.TopDirectoryOnly)
Dim text = File.ReadAllText(profile).Replace(
"UploadFolderConfiguration", "UploadProfileModel").Replace("TitlePrefill", "Title").Replace(
"AuthorPrefill", "Author").Replace("SubjectPrefill", "Subject").Replace(
"KeywordsPrefill", "Keywords").Replace("CategoryPrefill", "Category").Replace(
"TaxYearPrefill", "TaxYear")
File.WriteAllText(profile, text)
Next
End If
End Sub
End Class
43 changes: 43 additions & 0 deletions src/PDFKeeper.Common/AppPolicies.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'******************************************************************************
'* PDFKeeper -- Open Source PDF Document Management
'* Copyright (C) 2009-2022 Robert F. Frasca
'*
'* This file is part of PDFKeeper.
'*
'* PDFKeeper is free software: you can redistribute it and/or modify
'* it under the terms of the GNU General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'*
'* PDFKeeper is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'* GNU General Public License for more details.
'*
'* You should have received a copy of the GNU General Public License
'* along with PDFKeeper. If not, see <http://www.gnu.org/licenses/>.
'******************************************************************************
Public NotInheritable Class AppPolicies
''' <summary>
''' Application policy name type.
''' </summary>
Public Enum AppPolicy
DisableQueryAllDocuments
End Enum

''' <summary>
''' Gets the application policy value.
''' </summary>
''' <param name="policy">Policy name</param>
''' <returns>0 or 1</returns>
Public Shared Function GetValue(ByVal policy As AppPolicy) As Integer
If My.Computer.Registry.GetValue(String.Concat("HKEY_LOCAL_MACHINE\SOFTWARE\Policies\",
My.Application.Info.CompanyName, "\",
My.Application.Info.ProductName), policy.ToString,
Nothing) = 1 Then
Return 1
Else
Return 0
End If
End Function
End Class
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,35 @@
'* You should have received a copy of the GNU General Public License
'* along with PDFKeeper. If not, see <http://www.gnu.org/licenses/>.
'******************************************************************************
Public NotInheritable Class UploadFolderConfigurationTokens
Private Sub New()
' All members are shared.
End Sub

Public Shared ReadOnly Property DateToken As String
Public NotInheritable Class AppProperties
''' <summary>
''' Gets the application registry top level full key name.
''' </summary>
''' <returns>Registry key full name</returns>
Public Shared ReadOnly Property RegistryTopLevelKeyFullName As String
Get
Return My.Resources.DateToken 'yyyy-MM-dd
Return String.Concat("HKEY_CURRENT_USER\SOFTWARE\", My.Application.Info.CompanyName, "\",
My.Application.Info.ProductName)
End Get
End Property

Public Shared ReadOnly Property DateTimeToken As String
''' <summary>
''' Gets the PDFKeeper home page URI.
''' </summary>
''' <returns>URI</returns>
Public Shared ReadOnly Property HomePageUrl As Uri
Get
Return My.Resources.DateTimeToken 'yyyy-MM-dd HH:mm:ss
Return New Uri("https://www.pdfkeeper.org/")
End Get
End Property

Public Shared ReadOnly Property FileNameToken As String
''' <summary>
''' Gets the PDFKeeper AutoUpdater configuration file URI.
''' </summary>
''' <returns>URI</returns>
Public Shared ReadOnly Property AutoUpdaterConfigUri As Uri
Get
Return My.Resources.FileNameToken
Return New Uri("https://raw.githubusercontent.com/rffrasca/PDFKeeper/master/config/PDFKeeper.AutoUpdater.config.xml")
End Get
End Property

''' <summary>
''' Returns an object containing all Upload Folder Configuration Tokens as
''' an array.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function ToArray() As Object
Dim tokens As New GenericList(Of String)
tokens.Add(DateToken)
tokens.Add(DateTimeToken)
tokens.Add(FileNameToken)
Return tokens.ToArray(False)
End Function
End Class
Loading

0 comments on commit 9eb6614

Please sign in to comment.