Microsoft Small Basic

Program Listing: PLG039
'AUTOMATISCHE ERSTELLUNG DER UPDATETEXTDATEI

'WAS ICH NOCH MACHEN MUSS
'WENN IN DER EDtb ETWAS AKTUALISIERT WIRD, MUSS DIES IN DEN VARIABLEN ÜBERNOMMEN WERDEN
'IN DER PVtb DÜRFEN NUR ZAHLEN UND EIN PUNKT EINGEGEBEN WERDEN
'EINE FUNKTION EINBAUEN UM NACH DEM "CLEAR" VORGANG WIEDER DIE ALTEN WERTE HERZUSTELLEN UND UMGEKEHRT
'DAS LADEN VERVOLLSTÄNDIGEN!!! DIE WERTE AUS DER GELADENEN DATEI MÜSSEN ÜBERNOMMEN WERDEN
'LADEWARNUNG EINBAUEN! WENN SEIT DER LETZTEN SPEICHERUNG ETWAS GETAN WURDE = WARNUNG

Controls.ButtonClicked = BC
Controls.TextTyped = TT 'MUSS NOCH AKTUALISIERT WERDEN
'Timer.Tick = TIME 'WAHRSCHEINLICH UNNÖTIG
GraphicsWindow.MouseDown = MD

Graphicwin()
Graphic()
ProgDir()

Sub Graphicwin
progtitle = "Autoupdater Textfilecreator"
BCoptions = "normal"
GraphicsWindow.Height = 330
GraphicsWindow.Width = 860
GraphicsWindow.Top = Desktop.Height/2-GraphicsWindow.Height/2
GraphicsWindow.Left = Desktop.Width/2-GraphicsWindow.Width/2
GraphicsWindow.Title = progtitle

GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FontName = "Arial"
GraphicsWindow.FontSize = 12

randdif = 10
buthei = 28
butwit = 50
butwitxl = 120
tbhei = 23
tbwit = 300
directorykind = "IPD"
num = 4'3
numadd = 2 'Abhängig von dorectorykind (auch von der ersten Definierung)
vercount = 2
oldnums = ""
oldvers = ""
pos = 1
checkpath = ""
temppath = "C:\temp\AUTCtemp.txt"
' The following line could be harmful and has been automatically commented.
' File.WriteContents(temppath, "")
usedfile = ""
activebut = 1
startlinepos = 4
pv = ""
reset = ""
For i = 1 To 10'(57-48)
e = 47+i
goodlets[i] = Text.GetCharacter(e)
EndFor
cord["x"][1] = randdif-2
cord["y"][1] = randdif+128
cord["x"][2] = randdif-2
cord["y"][2] = randdif*2+128+buthei
cord["x"][3] = randdif*2+butwitxl-2
cord["y"][3] = randdif+128
cord["x"][4] = randdif*2+butwitxl-2
cord["y"][4] = randdif*2+128+buthei
cord["x"][5] = randdif*3+butwitxl*2-2
cord["y"][5] = randdif+128
EndSub

Sub Graphic
tutorialpic = ImageList.LoadImage(Program.Directory+"\AUTC tutorial.png")
tutorialsh = Shapes.AddImage(tutorialpic)
tutpich = 23
tutpicw = 100
picwebadr = "http://social.technet.microsoft.com/wiki/contents/articles/19708.small-basic-autoupdater-code-snippet.aspx"
Shapes.Move(tutorialsh, 1, GraphicsWindow.Height-tutpich)
Shapes.HideShape(tutorialsh)
GraphicsWindow.PenColor = "Green"
GraphicsWindow.BrushColor = "Green"
gchosebut = Shapes.AddRectangle(butwitxl+4, buthei+4)
GraphicsWindow.PenColor = "Red"
GraphicsWindow.BrushColor = "Red"
For i = 1 To 5
chosebut[i] = Shapes.AddRectangle(butwitxl+4, buthei+4)
EndFor
GraphicsWindow.PenColor = "Black"
GraphicsWindow.BrushColor = "Black"
Shapes.Move(gchosebut, cord["x"][1], cord["y"][1])
Shapes.Move(chosebut[1], cord["x"][1], cord["y"][1])
Shapes.Move(chosebut[2], cord["x"][2], cord["y"][2])
Shapes.Move(chosebut[3], cord["x"][3], cord["y"][3])
Shapes.Move(chosebut[4], cord["x"][4], cord["y"][4])
Shapes.Move(chosebut[5], cord["x"][5], cord["y"][5])
Shapes.HideShape(chosebut[1])

GraphicsWindow.FontSize = 18
shapetitle = Shapes.AddText("Create new update textfile")
GraphicsWindow.FontSize = 12
shapefn = Shapes.AddText("Filename")
shapepv = Shapes.AddText("Programversion")
shapeli = Shapes.AddText("Link")
shapedi = Shapes.AddText("Directory")
Shapes.Move(shapetitle, randdif, randdif)
Shapes.Move(shapefn, randdif, randdif*4+GraphicsWindow.FontSize+4)
Shapes.Move(shapepv, randdif, randdif*4+GraphicsWindow.FontSize+4+buthei+randdif)
Shapes.Move(shapeli, randdif, randdif*4+110+buthei+4+40)
Shapes.Move(shapedi, randdif, randdif*6+110+buthei+tbhei+4+40-5)
IPDbut = Controls.AddButton("Install PD", randdif, randdif+130)
IODbut = Controls.AddButton("Install OD", randdif, randdif*2+130+buthei)
DPDbut = Controls.AddButton("Delete PD", randdif*2+butwitxl, randdif+130)
DODbut = Controls.AddButton("Delete OD", randdif*2+butwitxl, randdif*2+130+buthei)
VERbut = Controls.AddButton("Version", randdif*3+butwitxl*2, randdif+130)
HEbut = Controls.AddButton("Help", GraphicsWindow.Width/2-butwit-randdif, randdif)
LObut = Controls.AddButton("Load", GraphicsWindow.Width/4-butwit*1.5-randdif*2, GraphicsWindow.Height-randdif-buthei)
SAbut = Controls.AddButton("Save", GraphicsWindow.Width/4-butwit/2-randdif, GraphicsWindow.Height-randdif-buthei)
ADbut = Controls.AddButton("Add", GraphicsWindow.Width/4+butwit/2+randdif, GraphicsWindow.Height-randdif-buthei)
CLbut = Controls.AddButton("Clear", GraphicsWindow.Width/4+butwit*1.5+randdif*2, GraphicsWindow.Height-randdif-buthei)
Controls.SetSize(IPDbut, butwitxl, buthei)
Controls.SetSize(IODbut, butwitxl, buthei)
Controls.SetSize(DPDbut, butwitxl, buthei)
Controls.SetSize(DODbut, butwitxl, buthei)
Controls.SetSize(VERbut, butwitxl, buthei)
Controls.SetSize(HEbut, butwit, buthei)
Controls.SetSize(LObut, butwit, buthei)
Controls.SetSize(SAbut, butwit, buthei)
Controls.SetSize(ADbut, butwit, buthei)
Controls.SetSize(CLbut, butwit, buthei)
FNtb = Controls.AddTextBox(120, randdif*4+GraphicsWindow.FontSize)
PVtb = Controls.AddTextBox(120, randdif*4+GraphicsWindow.FontSize+buthei+randdif)
LItb = Controls.AddTextBox(120, randdif*4+150+buthei)
DItb = Controls.AddTextBox(120, randdif*5.5+150+buthei+tbhei)
Controls.SetSize(FNtb, tbwit, tbhei)
Controls.SetSize(PVtb, tbwit/2.5, tbhei)
Controls.SetSize(LItb, tbwit, tbhei)
Controls.SetSize(DItb, tbwit, tbhei)

GraphicsWindow.PenWidth = 0.1
GraphicsWindow.DrawLine(430, 3, 430, GraphicsWindow.Height-3)
EDtb = Controls.AddMultiLineTextBox(GraphicsWindow.Width/2+randdif, randdif)
Controls.SetSize(EDtb, GraphicsWindow.Width/2-randdif*2, GraphicsWindow.Height-randdif*2)
GraphicsWindow.PenWidth = 1
EndSub

Sub ProgDir
progdire = Program.Directory
startlength = Text.GetLength(progdire)
pos = Text.GetIndexOf(progdire, "\")
vortext[1] = Text.GetSubText(progdire, 1, pos-1)
ubrigtext = Text.GetSubTextToEnd(progdire, pos+1)
e = 2
While pos > 0
pos = Text.GetIndexOf(ubrigtext, "\")
newlength = Text.GetLength(ubrigtext)
If pos = 0 Then
vortext[e] = "\\" + Text.GetSubText(progdire, startlength-newlength+1, Text.GetLength(ubrigtext))
Else
vortext[e] = "\\" + Text.GetSubText(progdire, startlength-newlength+1, pos-1)
ubrigtext = Text.GetSubTextToEnd(ubrigtext, pos+1)
e = e + 1
EndIf
EndWhile
For i = 1 To Array.GetItemCount(vortext)
checkpath = Text.Append(checkpath, vortext[i]) 'special version of the path. It is needed later.
EndFor
EndSub

Sub Filecheck
checkpath2 = checkpath+"\\"+Controls.GetTextBoxText(FNtb)+".txt"
' The following line could be harmful and has been automatically commented.
' locfiles = File.GetFiles(Program.Directory)
fileresult = Text.IsSubText(locfiles, checkpath2)
EndSub

Sub BC
LCB = Controls.LastClickedButton
If BCoptions = "normal" Then
If LCB = IPDbut Then
directorykind = "IPD"
activebut = 1
numadd = 2
ShapeMove()
ElseIf LCB = IODbut Then
directorykind = "IOD"
activebut = 2
numadd = 2
ShapeMove()
ElseIf LCB = DPDbut Then
directorykind = "DPD"
activebut = 3
numadd = 1
ShapeMove()
ElseIf LCB = DODbut Then
directorykind = "DOD"
activebut = 4
numadd = 1
ShapeMove()
ElseIf LCB = VERbut Then
directorykind = "VER"
activebut = 5
numadd = 1
ShapeMove()
ElseIf LCB = ADbut Then
Add()
ElseIf LCB = HEbut Then
Help()
ElseIf LCB = SAbut Then
Save()
ElseIf LCB = LObut Then
Load()
ElseIf LCB = CLbut Then
Clear()
EndIf
ElseIf BCoptions = "help" Then
If LCB = IPDbut Then
GraphicsWindow.ShowMessage("If this button is activated, your entered path will be combined with the program directory.", progtitle)
ElseIf LCB = IODbut Then
GraphicsWindow.ShowMessage("If this button is activated, your entered path will be used as it is.", progtitle)
ElseIf LCB = DPDbut Then
GraphicsWindow.ShowMessage("If this button is activated, your entered path will be combined with the program directory.", progtitle)
ElseIf LCB = DODbut Then
GraphicsWindow.ShowMessage("If this button is activated, your entered path will be used as it is.", progtitle)
ElseIf LCB = VERbut Then
GraphicsWindow.ShowMessage("If this button is activated, you will add a new version to your file."+Text.GetCharacter(10)+"Attention: After you added a new version, you can only add new entries to your old versions by hand.", progtitle)
ElseIf LCB = ADbut Then
GraphicsWindow.ShowMessage("If you press this button, you will add your entries to your file.", progtitle)
ElseIf LCB = HEbut Then
Help()
ElseIf LCB = SAbut Then
GraphicsWindow.ShowMessage("If you press this button, you can save your file.", progtitle)
ElseIf LCB = LObut Then
GraphicsWindow.ShowMessage("If you press this button, you can load a file.", progtitle)
ElseIf LCB = CLbut Then
GraphicsWindow.ShowMessage("If you press this button, your current progress will be deleted. But it doesn't delete a loaded or saved file.", progtitle)
EndIf
EndIf
EndSub

Sub Help
butcap = Controls.GetButtonCaption(HEbut)
If butcap = "Help" Then
Controls.SetButtonCaption(HEbut, "Back")
oldfntex = Controls.GetTextBoxText(FNtb)
oldpvtex = Controls.GetTextBoxText(PVtb)
oldlitex = Controls.GetTextBoxText(LItb)
oldditex = Controls.GetTextBoxText(DItb)
oldedtex = Controls.GetTextBoxText(EDtb)
Controls.SetTextBoxText(FNtb, "This is the name of your Updatefile.")
Controls.SetTextBoxText(PVtb, "That's the version of the program you are working on. Change it and press the 'Version' button to add a new version.")
Controls.SetTextBoxText(LItb, "This is URL of the file you want to download.")
Controls.SetTextBoxText(DItb, "This is the destination path of your file if you copy it and the delete path of the file you want to delete.")
Controls.SetTextBoxText(EDtb, "That's the preview window."+Text.GetCharacter(10)+"Here you can also change values manually."+Text.GetCharacter(10)+"ATTENTION: ONLY DO CHANGES HERE, IF YOU KNOW WHAT YOU DO!"+Text.GetCharacter(10)+"Otherwise you can destroy the whole file.")
BCoptions = "help"
Shapes.ShowShape(tutorialsh)
Controls.SetButtonCaption(HEbut, "Back")
ElseIf butcap = "Back" Then
Controls.SetTextBoxText(FNtb, oldfntex)
Controls.SetTextBoxText(PVtb, oldpvtex)
Controls.SetTextBoxText(LItb, oldlitex)
Controls.SetTextBoxText(DItb, oldditex)
Controls.SetTextBoxText(EDtb, oldedtex)
BCoptions = "normal"
Shapes.HideShape(tutorialsh)
Controls.SetButtonCaption(HEbut, "Help")
EndIf
EndSub

Sub MD
mox = GraphicsWindow.MouseX
moy = GraphicsWindow.MouseY
picl = 0
picr = picl+tutpicw
pict = GraphicsWindow.Height-tutpich
picb = GraphicsWindow.Height
If mox > picl And mox < picr Then
If moy > pict And moy < picb Then
AUoptions.OpenBrowserAt(picwebadr)
EndIf
EndIf
EndSub

Sub Load
lofilepath = AUoptions.FileBrowserTxt()
If lofilepath = "Error" Then
Else
' The following line could be harmful and has been automatically commented.
' trenner = Text.GetIndexOf(File.ReadLine(lofilepath, 2), "##;##")
' The following line could be harmful and has been automatically commented.
' Controls.SetTextBoxText(PVtb, Text.GetSubText(File.ReadLine(lofilepath, 2), 1, trenner-1))
sstartpos = Text.GetIndexOf(lofilepath, ".txt")'Position der Endung
startpos = sstartpos
f = 0 'f = FOUND
While f = 0
f = Text.GetIndexOf(Text.GetSubTextToEnd(lofilepath, startpos), "\")
If f = 0 Then
startpos = startpos-1
EndIf
EndWhile
length = Text.GetLength(lofilepath)-sstartpos+1
filename = Text.GetSubText(lofilepath, startpos+1, length)
Controls.SetTextBoxText(FNtb, filename) 'Der Dateiname wird aktualisiert
' The following line could be harmful and has been automatically commented.
' Controls.SetTextBoxText(EDtb, File.ReadContents(lofilepath)) 'Der Text in der EDtb wird aktualisiert
'VERVOLLSTÄNDIGEN, VARIABLEN MÜSSEN NOCH MIT WERTEN VERSEHEN WERDEN
' The following line could be harmful and has been automatically commented.
' File.WriteContents(temppath, File.ReadContents(lofilepath)) 'Die temporäre Datei wird aktualisiert
EndIf
EndSub

Sub Save 'SOBALD ICH AUCH IN ALLE BEREICHE KOPIEREN KANN, MUSS HIER EIN BROWSER ZUM WÄHLEN DES VERZEICHNISSES EINGEBAUT WERDEN
If AUoptions.EmptyCheck(Controls.GetTextBoxText(FNtb)) = "True" Then
AUoptions.AddOkMessage("You have to name your file before you can create it.", progtitle)
Else
Filecheck()
If fileresult = "True" Then
ynresult = MoreMessages.AddYesNoMessage("A file with this name already exists. Do you want to overwrite the file?", progtitle)
If ynresult = "Yes" Then
' The following line could be harmful and has been automatically commented.
' File.WriteContents(Program.Directory+"\"+Controls.GetTextBoxText(FNtb)+".txt", Controls.GetTextBoxText(EDtb))
EndIf
Else
' The following line could be harmful and has been automatically commented.
' res = File.WriteContents(Program.Directory+"\"+Controls.GetTextBoxText(FNtb)+".txt", Controls.GetTextBoxText(EDtb))
If res = "SUCCESS" Then
AUoptions.AddOkMessage("Done!", progtitle)
Else
AUoptions.AddOkMessage("Something went wrong. Sorry!", progtitle)
EndIf
EndIf
EndIf
EndSub

Sub ShapeMove
Shapes.Move(gchosebut, cord["x"][activebut], cord["y"][activebut]) 'Grünes Rechteck
For i = 1 To 5
Shapes.ShowShape(chosebut[i])
EndFor
Shapes.HideShape(chosebut[activebut])
EndSub

Sub Add
If AUoptions.EmptyCheck(Controls.GetTextBoxText(EDtb)) = "True" Then
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 1, vercount)
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 2, Controls.GetTextBoxText(PVtb)+"##;##"+Controls.GetTextBoxText(PVtb))
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 3, (num+numadd)+"##;##"+oldnums+startlinepos)
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 4, "Ver "+Controls.GetTextBoxText(PVtb))
oldvers = Controls.GetTextBoxText(PVtb)+"##;##"
oldnums = num+"##;##"
Else
' The following line could be harmful and has been automatically commented.
' trenner = Text.GetIndexOf(File.ReadLine(temppath, 3), "##;##")
' The following line could be harmful and has been automatically commented.
' rest = Text.GetSubTextToEnd(File.ReadLine(temppath, 3), trenner)
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 3, (num+numadd)+rest)
EndIf
If directorykind = "IPD" Then
slashres = Text.StartsWith(Controls.GetTextBoxText(DItb), "\")
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+1, "Down "+Controls.GetTextBoxText(LItb))
If slashres = "True" Then
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+2, "InstPD " +Controls.GetTextBoxText(DItb))
Else
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+2, "InstPD \" +Controls.GetTextBoxText(DItb))
EndIf
num = num+numadd
ElseIf directorykind = "IOD" Then
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+1, "Down "+Controls.GetTextBoxText(LItb))
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+2, "InstN "+Controls.GetTextBoxText(DItb))
num = num+numadd
ElseIf directorykind = "DPD" Then
slashres = Text.StartsWith(Controls.GetTextBoxText(DItb), "\")
If slashres = "True" Then
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+1, "DelePD " +Controls.GetTextBoxText(DItb))
Else
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+1, "DelePD \" +Controls.GetTextBoxText(DItb))
EndIf
num = num+numadd
ElseIf directorykind = "DOD" Then
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+1, "DeleN "+Controls.GetTextBoxText(DItb))
num = num+numadd
ElseIf directorykind = "VER" Then
vercount = vercount+1
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 1, vercount)
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 2, Controls.GetTextBoxText(PVtb)+"##;##"+oldvers+Controls.GetTextBoxText(PVtb))
startlinepos = num+numadd
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, 3, (num+numadd)+"##;##"+oldnums+startlinepos)
' The following line could be harmful and has been automatically commented.
' File.WriteLine(temppath, num+1, "Ver "+Controls.GetTextBoxText(PVtb))
oldnums = Text.Append(Text.Append(oldnums, (num+numadd)), "##;##")
oldvers = Text.Append(Text.Append(oldvers, Controls.GetTextBoxText(PVtb)), "##;##")
num = num+numadd
EndIf
' The following line could be harmful and has been automatically commented.
' Controls.SetTextBoxText(EDtb, File.ReadContents(temppath))
EndSub

Sub Clear
' The following line could be harmful and has been automatically commented.
' File.WriteContents(temppath, "")
Controls.SetTextBoxText(EDtb, "")
EndSub










'DIE MUSS ICH NOCH ÜBERARBEITEN
Sub TT
LTT = Controls.LastTypedTextBox
If LTT = PVtb Then
pv = Controls.GetTextBoxText(PVtb)
start = Text.GetLength(pv)
checklet = Text.GetSubTextToEnd(pv, start)
For i = 1 To Array.GetItemCount(goodlets)
If checklet = goodlets[i] Then
reset = Text.Append(reset, 0)
Else
reset = Text.Append(reset, 1)
EndIf
'TextWindow.WriteLine(Text.Append(checklet, Text.Append(" ", reset)))
EndFor
If Text.GetIndexOf(reset, 0) = 0 Then
Controls.SetTextBoxText(PVtb, pvold)
GraphicsWindow.ShowMessage("Only numbers and one point are allowed.", progtitle)
Else
TextWindow.WriteLine("The letter is ok!")
EndIf
EndIf
EndSub

'Sub TIME
' Timer.Pause()
' If aufgabe = 1 Then
' Filecheck()
' If fileresult = "True" Then
' ynresult = MoreMessages.AddYesNoMessage("A file with this name already exists. Do you want to load the file? (Otherwise the file is overwritten.", "Autoupdater Textfilecreator")
' If ynresult = "Yes" Then
' The following line could be harmful and has been automatically commented.
' ' Controls.SetTextBoxText(PVtb, File.ReadLine(checkpath2, 1))
' The following line could be harmful and has been automatically commented.
' ' Controls.SetTextBoxText(EDtb, File.ReadContents(checkpath2))
' usedfile = Controls.GetTextBoxText(FNtb)
' Else
' 'Nothing will happen. The file is overwritten.
' EndIf
' Else
' EndIf
' EndIf
'EndSub

'Sub PVinEDcheck
' pvtext = Controls.GetTextBoxText(PVtb)
' edtext = Controls.GetTextBoxText(EDtb)
' edtexlength = Text.GetLength(edtext)
' parag[1] = Text.GetIndexOf(edtext, Text.GetCharacter(10))
' vortext2 = Text.GetSubText(edtext, 1, parag[1]-1)
' ubrigtext2 = Text.GetSubTextToEnd(edtext, parag[1]+1)
' TextWindow.WriteLine(vortext2)'DEBUG
' TextWindow.WriteLine(ubrigtext2)'DEBUG
'EndSub

'HIER STÜRTZT DAS PROGRAM NOCH AB! IRGENDETWAS SETZT DEN PARAMETER "LENGTH" AUF UNTER 0
'Sub PVinEDchange
' newedtext = Text.Append(Controls.GetTextBoxText(PVtb), ubrigtext2)
' Controls.SetTextBoxText(EDtb, newedtext)
'EndSub
'HIER STÜRTZT DAS PROGRAM NOCH AB! IRGENDETWAS SETZT DEN PARAMETER "LENGTH" AUF UNTER 0