| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
Somebody else can have fist comment. That hurts my eyes too much to read through it.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:10
•
by
idfk
(unregistered)
|
|
inb4 .mkv!
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:15
•
by
Schmuli
(unregistered)
|
|
How is this zipping? What part of that script actually zips anything?
|
|
No wonder the C guys think VB sucks if this is their only experience of it!
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:19
•
by
Alan
(unregistered)
|
|
Jeez - just pay for Winzip command line already.
|
|
You're going to make me read code first thing Monday morning to find teh funnay? That's cold blooded... ;)
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:23
•
by
Tempura
(unregistered)
|
|
So, it's not a zip, but a self-extracting tar, disguised in vb. Not bad.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:25
•
by
Bill
(unregistered)
|
|
I like this:
CString m_outputfilename = m_outfile; CString outpath = outfolder; That's classy coding right there. He never uses outfile or outfolder again. He names them in the function, and then promptly renames them in the first two lines of the function. Quality stuff. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:27
•
by
AdT
(unregistered)
|
|
Mmmmm, meta-spaghetti. Things I like best:
- It never checks whether the whole fopen + fprintf stuff actually worked. - Declaring many variables in one scope, in particular "fileName" and "filename" - Assigning to "BOOL ret" only to use it just once - Declaring and assigning to the nested dwRetVal only to use it... never - Hard-coding "syswow64" - Assigning Nothing to variables at the end of the script, just in case... - Sleep 1000 of course :-) - If GetTempPath fails, open a file, append a string to an uninitialized buffer, then try to open another file without closing the first one. Priceless! |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:27
•
by
Phil
(unregistered)
|
It first creates a small empty ZIP file by actually writing a valid header (and nothing else) to the destination ZIP. It then uses the Windows shell extensions to add the required files to the ZIP via a "Copy" operation--like copying files from one folder to another. Since Windows treats ZIP files like folders that can be copied into, this adds them to the ZIP. Actually it's a rather clever idea to avoid the use of complex (sometimes unreliable) third-party libraries, but it's implemented a bit strangely. |
|
It looks like it uses vbscript to output a script to do the actual compression, then runs it.
It outputs an empty ZIP file and then uses the Windows Explorer ZIP shell extension to mimic the user ability to drag and drop files into that ZIP and have them automatically compressed. Clearly the programmer didn't know how to do this directly from C and couldn't be arsed to RTFM. Of course if the user disables the shell extension or is on an earlier Windows OS that doesn't have it, the program fails with no error. A more fool-proof solution would have been to use an external process like 7za.exe (7-zip), which, AFAIK, can be bundled as long as you include the license. Of course a library would be even better. |
|
this guy/girl is not stupid or inexperienced... the function is actually very clever ...
i love how the text file with the PK+magic number signature is written and it turns automatically into folder where the files are be copied ... |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:32
•
by
Anonymous
(unregistered)
|
|
Jesus Christ, this code has just made my day even worse.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:37
•
by
reaver121
(unregistered)
|
|
Sorry, couldn't resist :
My eyes ! The goggles, they do nothing !! |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:37
•
by
AdT
(unregistered)
|
|
Adding three more to my list:
- It's not even the same "FILE *fp", so this code just leaks a FILE no matter what. - "CString p" - Not only is it very bad style to declare the poorly-named lpPathBuffer1 at the start of the function although it is used only in a nested block. This buffer is also completely redundant. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:38
•
by
The_Assimilator
(unregistered)
|
Apart from the fact that the code itself is irredeemably retarded, I wonder if it'll work if Explorer isn't the handler for .zip files... |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:44
•
by
//my name
(unregistered)
|
|
The real WTF is the comments:
//find temp directory; dwRetVal = GetTempPath(dwBufSize, //buffer length lpPathBuffer); //path buffer //get the windows directory; dwRetVal = GetWindowsDirectory(lpPathBuffer1,dwBufSize); //path buffer Without these comments I'd have spend all of, err, 1 nano-second working out that GetTempPath let me find a temp directory and that GetWindowsDirectory would let me, err, get the windows directory. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 09:44
•
by
Phil
(unregistered)
|
Sure will. That's a totally different thing. |
|
Thank the lord for VB being a Windows only technology. The ZIP header and folder thing is very clever thought. What I don't seem to find is if this thing truly does any compression.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:01
•
by
MeBerserk
(unregistered)
|
|
I think C++ just scared the shit out of him and tried to solve it by using VB =)
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:06
•
by
Reader
(unregistered)
|
|
Real programmers can write VB in any language.
At least after someone showed them how to i/o-stream. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:17
•
by
dkf
|
Normally it will, if the system is relatively sanely configured. It's relying on Explorer's handling of the zip format to do the work for it. But goodness me, it's a fragile lash-up; if only there were zip tools that could be driven directly from the command line... (Making the header inside a .vbs file written from C++? Priceless.) |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:27
•
by
Frost
(unregistered)
|
|
The real WTF is that the attempt to be 64-bit compliant isn't correct.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:33
•
by
Anon
(unregistered)
|
|
With the Matryoshka doll comment I was expecting to see it zip individual files, then zip the folder of zip files recursively giving you a zip of zips of zips, and so on.
But this, is so much more insidiously retarded. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:37
•
by
Anon
(unregistered)
|
Or, repeatedly zip the same file until you reach the singularity of the 1 bit file. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:57
•
by
Dakman
(unregistered)
|
|
At first I just saw the large group of fprintf calls, and I thought "Okay, he's just writing a bunch of headers" then I looked closer and... Oh dear god no.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 10:58
•
by
St Mary's Hospital for the Sunken Donkeys
(unregistered)
|
|
He needed something in order to zip a folder full of files?
Geez... ...get tar and gzip. It's open source. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:03
•
by
hcs
(unregistered)
|
|
Yeah, I was expecting something that only added one file at a time to the zip, but that kept creating a zip and adding the previous zip to it instead so you end up with one file zipped N times instead of N files in a zip (or maybe adding one file with each level so you end up with something like a list in Lisp).
I guess the "nesting" is just the C program writing VB. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:04
•
by
halcyon1234
|
I've been doing that for a while now. I think the process is almost done. 1 <== The entire Internet. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:09
•
by
Tim
(unregistered)
|
|
"Jeez - just pay for Winzip command line already."
Glad you didn't write this either! The best solution would be to use the minizip library (in zlib/contrib). |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:13
•
by
configurator
(unregistered)
|
|
I like the way he runs "cmd.exe /c cscript //B " + filename instead of just "cscript /B " + filename...
|
|
TRWTF is that the "Full Article" view displays the exact same thing as the Summary view.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:20
•
by
drBeat
(unregistered)
|
|
misleading indentation:
if((fileName[0] != '\0')) And anyway, what is this RESID_30 string? A double quote? Couldn't he be bothered to look up how to escape a double quote inside A C++ string? |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:36
•
by
Scriptease
(unregistered)
|
|
"cmd.exe /c ..." spawns a new shell thread while "cscript /B" would block the program flow
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:46
•
by
Leak
|
Why reinvent the wheel? 42.zip exists... np: Tocotronic - Über Sex Kann Man Nur Auf Englisch Singen (Digital Ist Besser) |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:47
•
by
Lego
(unregistered)
|
Actually, once the zips of zips reached a sufficiently high level of disorder the combined size of all the zips would start to grow because each iteration adds a small amount of overhead to the file. Eventually the process would create a file consuming all secondary storage on the host system. -Lego |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 11:49
•
by
Leak
|
Except for the fact that CreateProcess does exactly that:
np: Louie Austen - Too Good To Last (Remix) (Too Good To Last) |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:04
•
by
Smash King
|
Alright class, this is a nice example of someone not getting the joke, or - even worse - getting the joke and still acting like it was serious. Now, can anyone point me where he failed his "Spot sarcasm" check? |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:08
•
by
James
(unregistered)
|
|
I don't know why everybody's acting like this makes their eyes bleed. Is it dumb to have your C++ code write your VBScript for you? Sure. But if you're stuck on an XP machine (and you know it will *always* be at least XP) and there are procedural hurdles to importing/using 3rd-party software, VBScript is the way to go. Sad, but true.
I grant you that he should have broken out the VBScript in a separate file and just invoked it as if it were a command-line zip util, but the basic concept is sound. Of course, I make no excuses for the quality of the rest of his code... |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:13
•
by
sxeraverx
(unregistered)
|
Whoosh! |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:15
•
by
Eyes bleeding
(unregistered)
|
This kind of stuff drives me crazy. No comments on the heart of the algorithm or on WTF s/he is doing... But s/he takes the time to tell us that dwBufSize is the size of the buffer and lpPathBuffer is the path buffer. Gee, thanks for nothing! |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:16
•
by
cod3_complete
|
Prime example of why comments should tell *why* not *what*. I only hope the young whippersnappers are listening. |
|
Hard coded paths = the programming equivalent of murdering kittens. Seriously. Don't put files on my damn C:\ drive root. I don't care if you can't find your temp folder.
Also: can't he just use the system environment variables that VBS already gives you? Aside from how retarded this is (what if you've disabled the Windows zip functionality? I know I have), it's actually kind of an intriguing solution. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:40
•
by
Anon
(unregistered)
|
No, no, no. You just don't have good enough compression algorithms. My project is to zip the entire contents of the universe down to a single bit which will then be tied to the state of the light switch in my office. Light switch on = universe exists Light switch off = ...well....you don't want to know what happens when I turn the lights off! Note to self: Leave a note for the cleaners telling them to please not turn off the lights. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:41
•
by
Anon
(unregistered)
|
All my comments look like this x = x + 1 // add 1 to x |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:42
•
by
Anon
(unregistered)
|
Yikes! I fail, left out the semi-colon x = x + 1; // add 1 to x Much better now. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:45
•
by
mh
(unregistered)
|
|
This one gives me a bad case of the bends.
Boom, tssssh, it's the way I tell 'em. |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:48
•
by
Lego
(unregistered)
|
Sorry, my mistake! I thought, for a moment, that intelligent discussion was a possibility in this forum. Silly me. -Name removed to protect the guilty |
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 12:57
•
by
Paladin
(unregistered)
|
|
it does only by virtue of the windows zipped folder does a standard compression on anything dragged&dropped or copied into it.
|
Re: Zipping Files - The Matryoshka Doll Way
2009-02-09 13:06
•
by
clm
(unregistered)
|
No, the singularity doesn't occur at a 1-bit file. You only reach a singularity if, after zipping it down to one bit, you zip it One More Time. It's at this point that the file collapses in on itself. |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |