OneManPen Posted March 5, 2012 Share Posted March 5, 2012 (edited) Sooo, I had a good idea a few days ago for a custom compression method. It's really simple and I'm sure alot of people have thought up of this before... All it does is searches for more then one copy of 4 char ... which it then replaces it with one character... now assuming I didn't do anything wrong this should decrese the file big time... but I most likely did something wrong since it tends to double in size Here's my code expandcollapse popup#include <string.au3> Opt("MustDeclareVars", 1) FileDelete(@ScriptDir & "\compression-log.txt") Global $m_file, $f_read, $f_Lenth, $r_chars, $c_save Global $count = 0 Global $symbols = "" $m_file = FileOpen(@ScriptDir & "\test.exe", 16) $f_read = FileRead($m_file) $c_save = $f_read ProgressOn("Searching", "Searching for matches") $f_Lenth = StringLen($f_read) Do local $x, $y, $z, $a $x = read_Chars() $y = $count / StringLen($f_read) * 100 ProgressSet($y) $z = StringInStr($f_read, $x, 0, 2) If $z <> 0 Then $a = set_Symbol() $c_save = StringReplace($c_save, $x, "-" & $a & "-") $f_read = StringReplace($f_read, $x, "") log_To_File("Match found using: " & $x & " compressing using " & $a) Else log_To_File("Searching for matches using: " & $x) EndIf Until $count >= StringLen($f_read) FileClose($m_file) ProgressOff() Msgbox(64, "Search is done", "Search has been completed" & @CRLF & "Compressed to " & StringLen($c_save) & " bytes") Func read_Chars() If $count == 0 Then $r_chars = StringLeft($f_read, 4) Else $r_chars = StringMid($f_read, $count, 4) EndIf $count = $count + 5 Return $r_chars EndFunc Func log_To_File($data) Local $file $file = FileOpen(@ScriptDir & "\compression-log.txt", 1) FileWrite($file, $data & @CRLF) FileClose($file) EndFunc Func record_Match($match, $data) local $file = @ScriptDir & "\temp.ini" ;IniRead($file, Found EndFunc Func set_Symbol() local $ran, $search, $x, $y = False While $y = False $ran = Random(1000, 9999) $ran = Round($ran) $ran = ChrW($ran) $x = StringInStr($symbols, $ran) If $x == 0 Then $symbols = $symbols & $ran & "," Return $ran $y = True Else log_To_File("Key already in use") EndIf WEnd Return $ran EndFunc Turns out binary is bigger then file contents themself Edited March 5, 2012 by SleeperCell42 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 5, 2012 Moderators Share Posted March 5, 2012 SleeperCell42,Please do not remove the title of your thread as it then cannot help anyone who searches for threads on the same problem later - just add [Fixed] if you so wish. And if you fixed it, it would be kind to post the solution for the same reason. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now