Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Unique - Class1.vb

Class1.vb

Caricato da: Totem
Scarica il programma completo

  1. Namespace Unique
  2.     Public Class FileFunctions
  3.         Public Shared Function Exists(ByVal nome As String) As Boolean
  4.             Exists = False
  5.             Try
  6.                 Dim w As New System.IO.StreamReader(nome)
  7.                 Return True
  8.             Catch erd As System.IO.FileNotFoundException
  9.                 Return False
  10.             End Try
  11.         End Function
  12.         Public Shared Sub Rename(ByVal nome1 As String, ByVal nome2 As String)
  13.             FileCopy(nome1, nome2)
  14.             Kill(nome1)
  15.         End Sub
  16.         Public Shared Function GetPath(ByVal name As String) As String
  17.             Dim s As String = ""
  18.             Dim i, a As Int16
  19.  
  20.             For i = 0 To name.Length - 1
  21.                 If name.Chars(i) = "\" Then
  22.                     a = i
  23.                 End If
  24.             Next
  25.             For i = 0 To a
  26.                 s = s & name.Chars(i)
  27.             Next
  28.             GetPath = s
  29.         End Function
  30.         Public Shared Function GetName(ByVal name As String) As String
  31.             Dim s As String = ""
  32.             Dim i, a As Int16
  33.  
  34.             For i = 0 To name.Length - 1
  35.                 If name.Chars(i) = "\" Then
  36.                     a = i
  37.                 End If
  38.             Next
  39.             For i = a To name.Length - 1
  40.                 If name.Chars(i) <> "." And i < name.Length - 4 Then
  41.                     s = s & name.Chars(i)
  42.                 Else
  43.                     Exit For
  44.                 End If
  45.             Next
  46.             GetName = s
  47.         End Function
  48.         Public Shared Function GetExtension(ByVal name As String) As String
  49.             Dim s As String = ""
  50.             Dim i, a As Int16
  51.  
  52.             For i = 0 To name.Length - 1
  53.                 If name.Chars(i) = "." Then
  54.                     a = i
  55.                 End If
  56.             Next
  57.             For i = a To name.Length - 1
  58.                 s = s & name.Chars(i)
  59.             Next
  60.             GetExtension = s
  61.         End Function
  62.         Public Shared Function Pos(ByVal toseek As String, ByVal inwhichfind As String) As Int64
  63.             'Algoritmo di ricerca lento
  64.             Dim a, b As Int64
  65.  
  66.             Pos = -1
  67.             For a = 0 To inwhichfind.Length - 1 'Esamina ogni carattere della stringa inwhichfind
  68.                 If inwhichfind.Chars(a) = toseek.Chars(0) Then 'Se il carattere numero a è uguale al primo carattere di toseek...
  69.                     For b = 0 To toseek.Length - 1 '...verifica che tutti i caratteri che lo seguono siano uguali a quelli di toseek
  70.                         If toseek.Chars(b) = inwhichfind.Chars(a + b) Then
  71.                             If b = toseek.Length - 1 Then
  72.                                 Return a 'E, in questo caso, ritorna l'indice del primo carattere di toseek in inwhichfind
  73.                             End If
  74.                         Else
  75.                             Pos = -1
  76.                             Exit For 'Altrimenti annulla il ciclo e continua il controllo
  77.                         End If
  78.                     Next
  79.                 Else
  80.                     Pos = -1
  81.                 End If
  82.             Next
  83.         End Function
  84.         Public Shared Function QuickSearch(ByVal ToSeek As String, ByVal InWhichFind As String) As Int16
  85.             'Algoritmo di ricerca veloce
  86.             Dim S As String = ""
  87.  
  88.             For i As Int16 = 0 To ToSeek.Length - 1
  89.                 S = S & InWhichFind.Chars(i)
  90.             Next
  91.  
  92.             For i As Int64 = ToSeek.Length To InWhichFind.Length - 1
  93.                 If S = ToSeek Then
  94.                     Return i
  95.                 End If
  96.                 S = S.Remove(0, 1)
  97.                 S = S & InWhichFind.Chars(i)
  98.             Next
  99.         End Function
  100.         Public Shared Function GetDirSize(ByVal Path As System.String) As Int64
  101.             Try
  102.                 Dim dirdata() As System.IO.DirectoryInfo
  103.                 Dim filedata() As System.IO.FileInfo
  104.                 Dim file As System.IO.FileInfo
  105.                 Dim dimension As Int64 = 0
  106.  
  107.  
  108.                 Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Path)
  109.                 ' Scansione dei file della directory
  110.                 filedata = dir.GetFiles("*.*")
  111.                 For Each file In filedata
  112.                     dimension = dimension + file.Length
  113.                 Next
  114.                 ' Scansione delle sottodirectory
  115.                 dirdata = dir.GetDirectories("*")
  116.                 For Each dir In dirdata
  117.                     dimension = dimension + GetDirSize(dir.FullName)
  118.                 Next
  119.                 Return dimension
  120.             Catch
  121.                 Return -1
  122.             End Try
  123.         End Function
  124.         Public Shared Function Cut(ByVal what As String) As String
  125.             'Tronca il nome di un file o di una cartella come
  126.             'se si lavorasse in ambiente DOS
  127.             Cut = ""
  128.  
  129.             'Se è un nome di file...
  130.             If QuickSearch(".", what) > -1 Then
  131.                 If what.Length <= 12 Then
  132.                     'Se il nome ha 8 caratteri, lascia invariato
  133.                     Return what
  134.                 Else
  135.                     Dim i As Int16
  136.  
  137.                     'Copia i primi sei caratteri del nome
  138.                     For i = 0 To 5
  139.                         Cut = Cut & what.Chars(i)
  140.                     Next
  141.                     'Aggiunge un ~1
  142.                     Cut = Cut & "~1"
  143.                     'Copia l'estensione in coda al nome
  144.                     For i = QuickSearch(".", what) To what.Length - 1
  145.                         Cut = Cut & what.Chars(i)
  146.                     Next
  147.                 End If
  148.                 'Se è il nome di una cartella...
  149.             Else
  150.                 If what.Length <= 8 Then
  151.                     Return what
  152.                 Else
  153.                     Dim i As Int16
  154.  
  155.                     'Copia i primi sei caratteri del nome
  156.                     For i = 0 To 5
  157.                         Cut = Cut & what.Chars(i)
  158.                     Next
  159.                     'Aggiunge un ~1
  160.                     Cut = Cut & "~1"
  161.                 End If
  162.             End If
  163.         End Function
  164.         Public Shared Function Pascal(ByVal par As String) As String
  165.             'Modifica il percorso di un file in modo che sia
  166.             'composto da nomi corti
  167.             Pascal = ""
  168.  
  169.             Dim i As Int16
  170.             Dim c As String = ""
  171.  
  172.             'Inizia il ciclo che controlla ogni carattere
  173.             For i = 0 To par.Length - 1
  174.                 'Se il carattere non è un backslash, lo copia
  175.                 'nella stringa buffer
  176.                 If par.Chars(i) <> "\" Then
  177.                     c = c & par.Chars(i)
  178.                 Else
  179.                     'Altrimenti aggiunge al percorso modificato
  180.                     'il nome corto della stringa buffer
  181.                     Pascal = Pascal & Cut(c) & "\"
  182.                     'E setta la stringa buffer a Nothing
  183.                     c = ""
  184.                 End If
  185.             Next
  186.             'Aggiunge in coda alla funzione il nome del file
  187.             'convertito in nome corto
  188.             Pascal = Pascal & Cut(c)
  189.         End Function
  190.     End Class
  191.     Public Class DateFunctions
  192.         Public Structure Data
  193.             Dim Year, Month As Int16
  194.             Dim Day, Hours, Minutes, Seconds As Byte
  195.             Dim Milli As Int16
  196.         End Structure
  197.         Public Shared Function CurrentYear() As Int32
  198.             Dim cont As New System.Windows.Forms.DateTimePicker
  199.             Return cont.Value.Year
  200.         End Function
  201.         Public Shared Function CurrentMonth() As Int16
  202.             Dim cont As New System.Windows.Forms.DateTimePicker
  203.             Return cont.Value.Month
  204.         End Function
  205.         Public Shared Function Today() As Int16
  206.             Dim cont As New System.Windows.Forms.DateTimePicker
  207.             Return cont.Value.Day
  208.         End Function
  209.         Public Shared Function CurrentHour() As Int16
  210.             Dim cont As New System.Windows.Forms.DateTimePicker
  211.             Return cont.Value.Hour
  212.         End Function
  213.         Public Shared Function CurrentMinute() As Int16
  214.             Dim cont As New System.Windows.Forms.DateTimePicker
  215.             Return cont.Value.Minute
  216.         End Function
  217.         Public Shared Function CurrentSecond() As Int16
  218.             Dim cont As New System.Windows.Forms.DateTimePicker
  219.             Return cont.Value.Second
  220.         End Function
  221.         Public Shared Function CurrentMilli() As Int16
  222.             Dim cont As New System.Windows.Forms.DateTimePicker
  223.             Return cont.Value.Millisecond
  224.         End Function
  225.         Public Shared Function Now() As Data
  226.             Dim M As Data
  227.  
  228.             M.Day = Today()
  229.             M.Hours = CurrentHour()
  230.             M.Milli = CurrentMilli()
  231.             M.Minutes = CurrentMinute()
  232.             M.Month = CurrentMonth()
  233.             M.Seconds = CurrentSecond()
  234.             M.Year = CurrentYear()
  235.  
  236.             Return M
  237.         End Function
  238.     End Class
  239.     Public Class Code
  240.         Public Function Crypt(ByVal s As String) As String
  241.             Dim i As Int64
  242.             Dim cifra As Int16
  243.             Crypt = ""
  244.  
  245.             For i = 0 To s.Length - 1
  246.                 cifra = Val(CType(i, String).Chars(CType(i, String).Length - 1))
  247.                 If Asc(s.Chars(i)) + cifra < 255 Then
  248.                     Crypt = Crypt & Chr(Asc(s.Chars(i)) + cifra)
  249.                 Else
  250.                     Crypt = Crypt & s.Chars(i)
  251.                 End If
  252.             Next
  253.             Return Crypt
  254.         End Function
  255.         Public Function DeCrypt(ByVal s As String) As String
  256.             Dim i As Int64
  257.             Dim cifra As Int16
  258.             DeCrypt = ""
  259.  
  260.             For i = 0 To s.Length - 1
  261.                 cifra = Val(CType(i, String).Chars(CType(i, String).Length - 1))
  262.                 If Asc(s.Chars(i)) - cifra < 0 Then
  263.                     DeCrypt = DeCrypt & s.Chars(i)
  264.                 Else
  265.                     DeCrypt = DeCrypt & Chr(Asc(s.Chars(i)) - cifra)
  266.                 End If
  267.             Next
  268.             Return DeCrypt
  269.         End Function
  270.     End Class
  271. End Namespace