Jump to content

Recommended Posts

  • Active+ Member

import md5,zlib,os
import sys
#import app

SUBFOLDER_CHECK = 0
target_folder = "D:/M2/Pvp/"
LogFile = 'Gtools_log.txt'
if not os.path.exists(LogFile):
	a=open(LogFile, "a")
	a.close()
	
def Log(wut):
    yaz=open(LogFile, "w")
    yaz.write(wut)
    yaz.close()
	
def Hata(wut):
    Log(wut)
    os.popen("start " + LogFile)
	#app.Exit()

def GetCrc(fileName):
	prev = 0
	for eachLine in open(fileName,"rb"):
		prev = zlib.crc32(eachLine, prev)
	crccikti = str("%X"%(prev & 0xFFFFFFFF))
	return crccikti.lower()
	
def GetMd5(file):
	m = md5.new()
	fp = open(file,"rb")
	while 1:
		data = fp.read(1024)
		if not data:break
		m.update(data)
	fp.close()
	hashcikti = m.hexdigest()
	return hashcikti.lower()

def GetSize(file):
	return str(os.path.getsize(file))
	
def ReturnHash(file,size,md5,crc):
	if GetMd5(file) != md5 : Hata("WRONG Md5: " + file)
	elif GetCrc(file) != crc: Hata("WRONG Crc: " + file)
	elif GetSize(file) != size: Hata("WRONG Size: " + file)
	
def SetFolderData(s):
	setdata=open(LogFile, "a")
	setdata.writelines(s + 'n')
	setdata.close()

def GetFolderData():
	global target_folder
	r = ""
	newlist = []
	liste = [f for f in os.listdir(target_folder) if os.path.isfile]
	if not SUBFOLDER_CHECK:
		for i in xrange(len(liste)):
			for c in liste:
				if int(GetSize(target_folder + c)) > 0:
					if "." in c:
						newlist.append©
			break
		for q in xrange(len(newlist)):
			for v in newlist:
				print "FILE: " + target_folder + v +  " SIZE: " + str(GetSize(target_folder + v)) +  " MD5: " + GetMd5(target_folder + v) + " CRC: " + GetCrc(target_folder + v)
				SetFolderData("		['" + target_folder + v +  "','" + str(GetSize(target_folder + v)) +  "','" + GetMd5(target_folder + v) + "','" + GetCrc(target_folder + v) + "']")
			break
		os.popen("start "+os.getcwd()+""+LogFile)
	if SUBFOLDER_CHECK:
		for root, dirs, files in os.walk(target_folder):
			path = root.split('/')   
			for file in files:
				if not path[-1] == "": r = '/'
				cikti = target_folder+str(path[-1])+r+file
				print cikti
				SetFolderData("		['" + target_folder.split("/")[-1]+str(path[-1])+r+file +  "','" + str(GetSize(cikti)) +  "','" + GetMd5(cikti) + "','" + GetCrc(cikti) + "']")
		os.popen("start "+os.getcwd()+""+LogFile)

def Control():
	#    FILE            SIZE                  MD5                     CRC
	FileList = [
		['uitaskbar.py','59801','38365e196f9d26dadf85a4e253f638c7','b1a49039'],
		['uitaskbar.pyc','49195','b2df8f9ba38a3db44baa648a4bfd705f','6ddf37d4'], 
	]
	for i in xrange(len(FileList)):
		for x in FileList:
			ReturnHash(x[0], x[1], x[2], x[3])
		break

###IF GET HASH
#GetFolderData()
###IF CHECK HASH
Control()
Mirror

 

I writing simple directory check script, you can check folder and subfolders hash(crc, md5) and size check

 

If you can get folder hash values activate Control() func, If you can check folder hash values activate GetFolderData() func.

  • Love 4
Link to comment
https://metin2.dev/topic/5500-folder-control-script/
Share on other sites

  • 3 weeks later...
  • 9 months later...

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.