|
-
Nov 20th, 2003, 09:46 AM
#1
Thread Starter
Fanatic Member
Temp Files Everywhere!!!!
My program creates temp files...Which is ok...Until you have over 400 of them on your hardrive. My program uses encryption to encrypt and decrypt passwords in an *.ini file.
I didnt create this encryption or decryption code so I wouldnt know how it works.
Does the code below cause the creation of hundreds of *.ini files?
Encrypt Code:
VB Code:
Private Sub cmdencrypt_Click()
On Error GoTo handler2
cmdencrypt.Enabled = False
cmddecrypt.Enabled = False
cmdexit.Enabled = False
Dim full, full2, temp, lin As String
temp = ""
If txtname.Text = "" Then
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
Exit Sub
End If
If (UCase(Right(txtname.Text, 3)) <> "TXT") And (UCase(Right(txtname.Text, 3)) <> "INI") And (UCase(Right(txtname.Text, 3)) <> "VBS") And (UCase(Right(txtname.Text, 3)) <> "INF") And (UCase(Right(txtname.Text, 3)) <> "BAT") Then
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
Exit Sub
End If
If Right(Dir1.Path, 1) = "\" Then
full = txtname.Text
full2 = App.Path & "\temp.tmp"
Else
full = txtname.Text
full2 = App.Path & "\temp.tmp"
End If
Open full For Input As #3
Line Input #3, emp
Close #3
If emp = "" Then
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
Exit Sub
End If
chksum = "[§Encrypted§]"
Open full For Input As #1
Line Input #1, chks
Close #1
If (chks = chksum) Then
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
Exit Sub
End If
StatusBar1.SimpleText = " Status: Encryption in progress...."
Open full2 For Output As #3
Print #3, chksum
Close #3
Open full For Input As #1
While Not EOF(1)
Line Input #1, lin
Open full2 For Append As #3
rev = reverse(lin)
For I = 1 To Len(lin)
encryptfactor = Len(lin) Mod 10
If encryptfactor = 0 Then
encryptfactor = Int(Len(lin) / 10)
End If
A = Mid(rev, I, 1)
B = Asc(A) + encryptfactor
If B > 255 Then
B = 255
End If
temp = temp & Chr(B)
Next
Print #3, temp
temp = ""
Close #3
Wend
Close #1
Kill (full)
FileCopy full2, full
Kill (full2)
StatusBar1.SimpleText = " Status: Encryption completed !"
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
StatusBar1.SimpleText = " Status: Ready"
Exit Sub
handler2:
s = MsgBox(Err.Description, vbExclamation, "Error !")
g = Dir(full2)
If g <> "" Then
Kill (full2)
End If
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
End Sub
And Here is the decrypt code:
VB Code:
Private Sub cmddecrypt_Click()
On Error GoTo handler
cmdencrypt.Enabled = False
cmddecrypt.Enabled = False
cmdexit.Enabled = False
If txtname.Text = "" Then
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
Exit Sub
End If
If (UCase(Right(txtname.Text, 3)) <> "TXT") And (UCase(Right(txtname.Text, 3)) <> "INI") And (UCase(Right(txtname.Text, 3)) <> "VBS") And (UCase(Right(txtname.Text, 3)) <> "INF") And (UCase(Right(txtname.Text, 3)) <> "BAT") Then
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
Exit Sub
End If
If Right(Dir1.Path, 1) = "\" Then
full = txtname.Text
full2 = App.Path & "\temp.tmp"
Else
full = txtname.Text
full2 = App.Path & "\temp.tmp"
End If
Open full For Input As #4
Line Input #4, chk
Close #4
If (chk <> "[§Encrypted§]") Then
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
Exit Sub
End If
StatusBar1.SimpleText = " Status: Decryption in progress...."
Open full For Input As #1
Line Input #1, k
While Not EOF(1)
Line Input #1, lin
Open full2 For Append As #3
rev = reverse(lin)
For I = 1 To Len(lin)
decryptfactor = Len(lin) Mod 10
If decryptfactor = 0 Then
decryptfactor = Int(Len(lin) / 10)
End If
A = Mid(rev, I, 1)
B = Asc(A) - decryptfactor
temp = temp & Chr(B)
Next
Print #3, temp
temp = ""
Close #3
Wend
Close #1
Kill (full)
FileCopy full2, full
Kill (full2)
StatusBar1.SimpleText = " Status: Decryption completed !"
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
StatusBar1.SimpleText = " Status: Ready"
Exit Sub
handler:
s = MsgBox(Err.Description, vbExclamation, "Error !")
g = Dir(full2)
If g <> "" Then
Kill (full2)
End If
cmdencrypt.Enabled = True
cmddecrypt.Enabled = True
cmdexit.Enabled = True
End Sub
The part of this code that bothers me is:
VB Code:
full = app.path & "\temp.tmp"
-
Nov 20th, 2003, 10:11 AM
#2
Frenzied Member
When you say 100's do you mean 100's every time that code runs?
Or do you mean it creates one file, but the code is actually run 100's of times over a week / month / year??
And is it the decrypt that creates the files? Or the encrypt?
-
Nov 20th, 2003, 10:16 AM
#3
Thread Starter
Fanatic Member
I mean over a period of time. Like about 100 will be created over a week. And I dont know if the encrypt or decrypt creates the temp files. But I noticed it creates temp files in the app.path. Can I get rid off Full2? And if so how...because when I tried to I got errors.
-
Nov 20th, 2003, 03:00 PM
#4
Thread Starter
Fanatic Member
just sending my post to the top of the forum...
-
Nov 20th, 2003, 05:10 PM
#5
cid
What are the file names of the temp files?
-
Nov 21st, 2003, 09:35 AM
#6
Thread Starter
Fanatic Member
Like...
2C.tmp
18.tmp
10.tmp
Just junk like that.
-
Nov 21st, 2003, 03:13 PM
#7
Addicted Member
I have the same problem with one of my apps. I just put this code in to clean up the .tmp files when my app starts each time. You don't do this during program operation as the .tmp file may be in use. The extension .tmp means temporary so it is not needed after the program has ended.
-
Nov 21st, 2003, 03:46 PM
#8
Thread Starter
Fanatic Member
Sweet...Thanks purdybirds. Ill try what you said and get back to you in about a week...Cause the project is at school and school is closed due to holidays.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|