vb.net - Blocking more folders and applications -


as can see here block directory called "cleo". if have in folder can't click connect. how can check if, example, "cleo", "images", "logs" exist in browsed file. don't think making multiple if statements good, there other way?

    private sub connect_click(byval sender system.object, byval e system.eventargs) handles connect.click         dim cleopath string         dim filepath string         filepath = system.io.path.combine(textbox2.text, "gta_sa.exe")         cleopath = system.io.path.combine(textbox2.text, "cleo")          if file.exists(filepath)             if directory.exists(cleopath)                 msgbox("pronasli smo cleo fajl u vasem gta root folderu. da se konektujete na server morate ga obrisati.")             else                 dim p() process                 p = process.getprocessesbyname("samp")                 if p.count > 0                     msgbox("vec imate pokrenut samp - ugasite ga.")                 else                     try                         dim prozess process = process.getprocessesbyname("samp")(0)                         prozess.kill()                     catch ex exception                      end try                     my.computer.registry.setvalue("hkey_current_user\software\samp", "playername", textbox1.text)                     process.start("samp://193.192.58.55:7782")                      dim client new tcpclient                     client.connect("193.192.58.55", 10924)                     dim sendbytes() byte = system.text.encoding.ascii.getbytes(textbox1.text)                     dim stream networkstream = client.getstream()                     stream.write(sendbytes, 0, sendbytes.length)                 end if             end if         else             msgbox("da se konektujete morate locirati gta san andreas folder.")         end if     end sub end class 

you use extension methods combined directoryinfo check if of list of directory exists. depending of if want true/false return or if need process each directories (for instance, adding custom message name of folders prevent application continuing.

public module directoryinfoext <system.runtime.compilerservices.extension()> public function anyexists(dirinfo io.directoryinfo, paramarray directories string()) boolean     dim mypath string = dirinfo.fullname.trimend("\"c) & "\"     return directories.any(function(dir) io.directory.exists(mypath & dir)) end function  <system.runtime.compilerservices.extension()> public function getexistingdirectories(dirinfo io.directoryinfo, paramarray directories string()) ienumerable(of string)     dim mypath string = dirinfo.fullname.trimend("\"c) & "\"     return directories.where(function(dir) io.directory.exists(mypath & dir)) end function end module 

an example boolean return.

dim basedirectory string = "c:\games\gta"     dim gamepath new directoryinfo(basedirectory)      ' not give specific path exists, boolean if of theses folder found     dim modsfound boolean = gamepath.anyexists("images", "cleo", "logs", "somefolder\subfolder")      if not modsfound         'connect     else         '     end if 

an example using list return generate custome message prompt stating name of specific folders found.

'this version gives list instead.     dim modsfoundlist ienumerable(of string) = gamepath.getexistingdirectories("images", "cleo", "logs", "somefolder\subfolder")     dim hasmod boolean = modsfoundlist.count > 0      if hasmod         evilmoddeduserprompt(modsfoundlist)         exit sub     end if      ' here, since hasmod false, can proceed connection.     ' connection 

as evilmoddeduserprompt method

public sub evilmoddeduserprompt(modsfoundlist list(of string))     dim outputmessage new text.stringbuilder     outputmessage.appendline("the following mods have been detected on system:")     each moditem string in modsfoundlist         outputmessage.appendformat("- {0}", moditem)         outputmessage.appendline()     next     messagebox.show(outputmessage.tostring)  end sub 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -