OmagPHOTO :
- Aggiunti backup di sicurezza.
This commit is contained in:
@@ -50,6 +50,8 @@ Module ConstGen
|
||||
Public Const TEMP_DIR As String = "Temp"
|
||||
' Sottodirettorio per Img automatico
|
||||
Public Const IMGAUTO_DIR As String = "ImgAuto"
|
||||
' Sottodirettorio per BackUp
|
||||
Public Const BACKUP_DIR As String = "BackUp"
|
||||
|
||||
' Costanti per lavorazioni
|
||||
Public Const PHOTO_GRP As String = "Photos"
|
||||
|
||||
@@ -86,6 +86,13 @@ Public Class MainWindowM
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private m_sBackUpDir As String
|
||||
Friend ReadOnly Property sBackUpDir As String
|
||||
Get
|
||||
Return m_sBackUpDir
|
||||
End Get
|
||||
End Property
|
||||
|
||||
#End Region ' FIELDS
|
||||
|
||||
#Region "CONSTRUCTOR"
|
||||
@@ -110,6 +117,8 @@ Public Class MainWindowM
|
||||
m_sTempDir = m_sDataRoot & "\" & TEMP_DIR
|
||||
' Impostazione path Ini file
|
||||
IniFile.m_sIniFile = m_sConfigDir & "\" & INI_FILE_NAME
|
||||
' Impostazione direttorio per backup
|
||||
m_sBackUpDir = m_sDataRoot & "\" & BACKUP_DIR
|
||||
' Verifico indice di istanza
|
||||
ManageInstance()
|
||||
' Imposto tipo di chiave
|
||||
|
||||
@@ -74,6 +74,9 @@ Public Class MainWindowVM
|
||||
If m_MainWindowM.GetKeyOption(KEY_OPT.MAN_PHOTO) Then
|
||||
m_Camera.Init()
|
||||
End If
|
||||
' Eseguo backup del Db
|
||||
ManageDb.ManageBackUp()
|
||||
'ManageDb.CreateFileToClear()
|
||||
End Sub
|
||||
|
||||
#End Region ' METHODS
|
||||
|
||||
@@ -59,5 +59,5 @@ Imports System.Windows
|
||||
' by using the '*' as shown below:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.9.6.1")>
|
||||
<Assembly: AssemblyFileVersion("1.9.6.1")>
|
||||
<Assembly: AssemblyVersion("1.9.6.2")>
|
||||
<Assembly: AssemblyFileVersion("1.9.6.2")>
|
||||
|
||||
@@ -15,6 +15,8 @@ Module ManageDb
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private BackUpDbCallBack As New SQLiteBackupCallback(AddressOf BackUpDbCallBackFunction)
|
||||
|
||||
#End Region ' FIELDS & PROPERTIES
|
||||
|
||||
#Region "METHODS"
|
||||
@@ -90,6 +92,97 @@ Module ManageDb
|
||||
Return SlabList
|
||||
End Function
|
||||
|
||||
Friend Function ManageBackUp() As Boolean
|
||||
ClearBackUps()
|
||||
Dim BackUpDbPath As String = Map.refMainWindowVM.MainWindowM.sBackUpDir & "\" & Path.GetFileNameWithoutExtension(DB_FILENAME) & Date.Now.ToString("yyyy-MM-dd_HH-mm-ss") & ".sqlite"
|
||||
SQLiteConnection.CreateFile(BackUpDbPath)
|
||||
Using BackUpDbConnection As New SQLiteConnection("Data Source = " & BackUpDbPath & "; Version=3;")
|
||||
m_DbConnection.Open()
|
||||
BackUpDbConnection.Open()
|
||||
m_DbConnection.BackupDatabase(BackUpDbConnection, "main", "main", -1, BackUpDbCallBack, 0)
|
||||
m_DbConnection.Close()
|
||||
BackUpDbConnection.Close()
|
||||
End Using
|
||||
Map.refStatusBarVM.SetLoadingProgress(100)
|
||||
Map.refStatusBarVM.SetLoadingProgress_Visibility(False)
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Sub ClearBackUps()
|
||||
Try
|
||||
Dim bMonthMaintain() As Boolean = {False, False, False, False, False, False, False, False, False, False, False, False}
|
||||
Dim bWeekMaintain() As Boolean = {False, False, False, False}
|
||||
For Each file As IO.FileInfo In New IO.DirectoryInfo(Map.refMainWindowVM.MainWindowM.sBackUpDir).GetFiles("*.sqlite").OrderBy(Function(f) f.CreationTime)
|
||||
If (Now - file.CreationTime).Days > 30 Then
|
||||
For I = 12 To 2 Step -1
|
||||
If (Now - file.CreationTime).Days <= 30.5 * I AndAlso (Now - file.CreationTime).Days > 30.5 * (I - 1) Then
|
||||
If Not bMonthMaintain(I - 1) Then
|
||||
bMonthMaintain(I - 1) = True
|
||||
Exit For
|
||||
Else
|
||||
file.Delete()
|
||||
Exit For
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
ElseIf (Now - file.CreationTime).Days > 28 Then
|
||||
file.Delete()
|
||||
Continue For
|
||||
Else
|
||||
For I = 4 To 2 Step -1
|
||||
If (Now - file.CreationTime).Days <= 7 * I AndAlso (Now - file.CreationTime).Days > 7 * (I - 1) Then
|
||||
If Not bWeekMaintain(I - 1) Then
|
||||
bWeekMaintain(I - 1) = True
|
||||
Exit For
|
||||
Else
|
||||
file.Delete()
|
||||
Exit For
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
Catch ex As Exception
|
||||
EgtOutLog(ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Friend Sub CreateFileToClear()
|
||||
Try
|
||||
Dim MostRecentFile As IO.FileInfo = Nothing
|
||||
For Each CurrFile As IO.FileInfo In New IO.DirectoryInfo(Map.refMainWindowVM.MainWindowM.sBackUpDir).GetFiles("*.sqlite")
|
||||
If Not IsNothing(MostRecentFile) Then
|
||||
If (MostRecentFile.CreationTime < CurrFile.CreationTime) Then
|
||||
File.Delete(MostRecentFile.FullName)
|
||||
MostRecentFile = CurrFile
|
||||
Else
|
||||
File.Delete(CurrFile.FullName)
|
||||
End If
|
||||
Else
|
||||
MostRecentFile = CurrFile
|
||||
End If
|
||||
Next
|
||||
If IsNothing(MostRecentFile) Then Return
|
||||
For I = 0 To 365
|
||||
Dim CreationDate As Date = Date.Now.AddDays(-I)
|
||||
Dim NewFilePath As String = Map.refMainWindowVM.MainWindowM.sBackUpDir & "\" & Path.GetFileNameWithoutExtension(DB_FILENAME) & CreationDate.ToString("yyyy-MM-dd_HH-mm-ss") & ".sqlite"
|
||||
File.Copy(MostRecentFile.FullName, NewFilePath)
|
||||
File.SetCreationTime(NewFilePath, CreationDate)
|
||||
File.SetLastAccessTime(NewFilePath, CreationDate)
|
||||
File.SetLastWriteTime(NewFilePath, CreationDate)
|
||||
Next
|
||||
File.Delete(MostRecentFile.FullName)
|
||||
Catch ex As Exception
|
||||
EgtOutLog(ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Function BackUpDbCallBackFunction(source As SQLiteConnection, sourceName As String, destination As SQLiteConnection, destinationName As String, pages As Integer, remainingPages As Integer, totalPages As Integer, retry As Boolean) As Boolean
|
||||
Map.refStatusBarVM.SetLoadingProgress_Visibility(True)
|
||||
Map.refStatusBarVM.SetLoadingProgress(100% * (totalPages - remainingPages) / totalPages)
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Friend Sub AddRandomRows(nRow As Integer)
|
||||
Dim ImagePathList() As String = {"c:\EgtData\OmagPHOTO\Data\Lastra15_18.jpg",
|
||||
"c:\EgtData\OmagPHOTO\Data\Lastra18_10.jpg",
|
||||
|
||||
Reference in New Issue
Block a user