-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d94c90
commit 82c0aa4
Showing
12 changed files
with
423 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
Imports System.IO | ||
Imports Devart.Data | ||
Imports Devart.Data.SQLite | ||
|
||
Module FindWatchtower | ||
Function findWatchtowerDirectory() As String | ||
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\Packages" | ||
If IO.Directory.Exists(path) Then | ||
For Each Dir As String In Directory.GetDirectories(path) | ||
If LCase(Dir).Contains("watchtower") Then | ||
path = Dir & "\LocalState\Publications" | ||
Exit For | ||
End If | ||
Next | ||
End If | ||
If IO.Directory.Exists(path) Then Return path Else Return "" | ||
End Function | ||
|
||
Function existWhatchtowerDirectory() As Boolean | ||
If findWatchtowerDirectory() <> "" Then Return True Else Return False | ||
End Function | ||
|
||
Function findCurrentWatchtowers() As List(Of String) 'I used an array in case there were multiple languages | ||
Dim wtPath As String = findWatchtowerDirectory() | ||
Dim collectionPath As String = wtPath.Replace("\Publications", "\Data\pub_collections.db") | ||
Dim pubArray As New List(Of publication) | ||
If System.IO.File.Exists(collectionPath) Then | ||
Using sqlCon As New SQLiteConnection(String.Format("Data Source = {0}", collectionPath)) | ||
Dim query As String = "SELECT IssueTagNumber, FirstDatedTextDateOffset, LastDatedTextDateOffset, KeySymbol FROM Publication" | ||
sqlCon.Open() | ||
Using command = sqlCon.CreateCommand() | ||
command.CommandText = query | ||
Using reader = command.ExecuteReader() | ||
While reader.Read() | ||
Dim pub As publication = New publication | ||
pub.tagNumber = reader.GetString(0) | ||
pub.firstDate = reader.GetString(1) | ||
pub.lastDate = reader.GetString(2) | ||
pub.keySymbol = reader.GetString(3) | ||
pubArray.Add(pub) 'Getting all publications | ||
End While | ||
End Using | ||
End Using | ||
sqlCon.Dispose() : sqlCon.Close() : GC.Collect() : GC.WaitForPendingFinalizers() | ||
End Using | ||
End If | ||
|
||
Dim wtArray As New List(Of publication) | ||
For Each pub In pubArray | ||
If pub.keySymbol = "w" Then wtArray.Add(pub) 'Keeping only watchtowers | ||
Next | ||
|
||
Dim currentTagN As String = "" | ||
For Each pub In wtArray | ||
Dim firstDate As Date = DateTime.ParseExact(pub.firstDate, "yyyyMMdd", Nothing) | ||
Dim lastDate As Date = DateTime.ParseExact(pub.lastDate, "yyyyMMdd", Nothing) | ||
Dim todayDate As Date = Now.Date | ||
If firstDate <= todayDate And todayDate <= lastDate Then 'Period checking | ||
currentTagN = pub.tagNumber | ||
Exit For | ||
End If | ||
Next | ||
|
||
Dim wtDirArray As New List(Of String) | ||
For Each pubDirectory In IO.Directory.EnumerateDirectories(wtPath) | ||
Dim pubName As String = pubDirectory.ToString.Split("\").Last | ||
If Not pubName.Contains("w_") Or currentTagN.Length < 6 Then GoTo _endFor | ||
If pubName.StartsWith("w_") And pubName.EndsWith(currentTagN.Substring(0, 6)) Then 'Getting watchtower directories | ||
wtDirArray.Add(pubDirectory) | ||
End If | ||
_endFor: | ||
Next | ||
|
||
Return wtDirArray | ||
End Function | ||
End Module | ||
|
||
Structure publication | ||
Dim keySymbol As String | ||
Dim tagNumber As String | ||
Dim firstDate As String | ||
Dim lastDate As String | ||
End Structure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Imports Devart.Data | ||
Imports Devart.Data.SQLite | ||
|
||
Module FindWeekWT | ||
Function GetWeekN(ByVal dbDir As String) As Integer | ||
If Not System.IO.File.Exists(dbDir) Then Return -1 | ||
Dim returnID As Integer = -1 | ||
Using sqlCon As New SQLiteConnection(String.Format("Data Source = {0}", dbDir)) | ||
Dim readWeekQuery As String = "SELECT DatedTextId, FirstDateOffset, LastDateOffset FROM DatedText" | ||
sqlCon.Open() | ||
Using command = sqlCon.CreateCommand() | ||
command.CommandText = readWeekQuery | ||
Using reader = command.ExecuteReader() | ||
While reader.Read() | ||
Dim id = reader.GetInt32(0) | ||
Dim firstDate = reader.GetString(1) | ||
Dim lastDate = reader.GetString(2) | ||
If CheckWTWeek(firstDate, lastDate) Then returnID = id | ||
End While | ||
End Using | ||
End Using | ||
sqlCon.Dispose() : sqlCon.Close() : GC.Collect() : GC.WaitForPendingFinalizers() | ||
End Using : Return returnID | ||
End Function | ||
|
||
Function CheckWTWeek(ByVal firstDate As String, ByVal lastDate As String) As Boolean | ||
Dim startDate As Date = DateTime.ParseExact(firstDate, "yyyyMMdd", Nothing) | ||
Dim endDate As Date = DateTime.ParseExact(lastDate, "yyyyMMdd", Nothing) | ||
If Now.Date >= startDate And Now.Date <= endDate Then Return True Else Return False | ||
End Function | ||
|
||
Function GetDocumentID(ByVal dbDir As String, ByVal weekN As Integer) As Integer | ||
If Not System.IO.File.Exists(dbDir) Then Return -1 | ||
Dim returnID As Integer = -1 | ||
Using sqlCon As New SQLiteConnection(String.Format("Data Source = {0}", dbDir)) | ||
Dim readWeekQuery As String = "SELECT DocumentId, Class FROM Document" | ||
sqlCon.Open() | ||
Using command = sqlCon.CreateCommand() | ||
command.CommandText = readWeekQuery | ||
Dim actWeekN As Integer = 1 | ||
Using reader = command.ExecuteReader() | ||
While reader.Read() | ||
Dim id = reader.GetInt32(0) | ||
Dim class_ = reader.GetInt32(1) | ||
If class_ = 40 Then | ||
If weekN = actWeekN Then returnID = id | ||
actWeekN += 1 | ||
End If | ||
End While | ||
End Using | ||
End Using | ||
sqlCon.Dispose() : sqlCon.Close() : GC.Collect() : GC.WaitForPendingFinalizers() | ||
End Using : Return returnID | ||
End Function | ||
End Module |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.