Files
LicenceManager/Utility/ManageFile.vb
T
Dario Sassi f4f19bb8f0 LicenceManager 2.5j1 :
- aggiornamenti vari.
2023-10-09 13:11:06 +02:00

42 lines
2.0 KiB
VB.net

Imports System.IO
Module ManageFile
Public Function ComputeFileName(FilePath As String, FileNameOnly As String) As String
' Resetto il nome del file (in modo che sia senza '_' e numero) e cerco nel DB se è già presente un file con lo stesso nome
FilePath = Path.GetDirectoryName(FilePath) & "\" & FileNameOnly.Split("_"c)(0) & ".Kge"
FilePath = FilePath.Replace("\", "\\")
Dim sFileNameQuery = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_FILE & " = '" & FilePath & "' "
Dim m_UpdateLicDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(sFileNameQuery)
If m_UpdateLicDict.ContainsKey(DB_FILE) AndAlso Not String.IsNullOrWhiteSpace(m_UpdateLicDict(DB_FILE)) Then
' Se il nome del file già esiste procedo col loop per il calcolo del numero dopo '_'
FilePath = FilePath.Replace("\\", "\")
Dim fileNumber As Integer = 0
Do
FilePath = FilePath.Replace("\", "\\")
sFileNameQuery = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_FILE & " = '" & FilePath & "' "
m_UpdateLicDict = ManageDb.ExecuteStringDictionaryQuery(sFileNameQuery)
If m_UpdateLicDict.ContainsKey(DB_FILE) AndAlso Not String.IsNullOrWhiteSpace(m_UpdateLicDict(DB_FILE)) Then
'The file does exist, so increment and try the next one
fileNumber = fileNumber + 1
FilePath = FilePath.Replace("\\", "\")
If fileNumber = 1 Then
FilePath = FilePath.Replace(".Kge", "") & "_1.Kge"
Else
FilePath = FilePath.Replace((fileNumber - 1).ToString & ".Kge", "") & fileNumber.ToString & ".Kge"
End If
Else
'The file does not exist, do something..
If fileNumber = 1 Then
FilePath = FilePath.Split("_"c)(0) & "_1.Kge"
End If
Exit Do
End If
Loop
End If
FilePath = FilePath.Replace("\\", "\")
Return FilePath
End Function
End Module