• (cs)

    Well, the code isn't great, but what if this was a quick lash up that someone made up to get a quick job done? Maybe they started it and pulled onto something else?

    Sometimes you lot just like to pick holes in everything - are you all saying that your code and scripts are perfect everytime (even whilst 'in progress')?

    If it works, and it's a useful tool, just use it - don't whinge about it.

  • Anonymous (unregistered) in reply to Postie
    Postie:
    ...are you all saying that your code and scripts are perfect everytime (even whilst 'in progress')?...
    Well yes, actually.
  • BK (unregistered) in reply to Postie
    Postie:
    Sometimes you lot just like to pick holes in everything - are you all saying that your code and scripts are perfect everytime (even whilst 'in progress')?

    If it works, and it's a useful tool, just use it - don't whinge about it.

    The code makes some assumptions which are outside of a control of the original developer and are not verified in the code either. As a result of these assumptions, it will fail in mysterious ways when any of these assumptions is violated. Perhaps the whole functionality is bogus and nothing will actually happen when the whole thing fails, but I do not know that. I assume there would be some loss of productivity fixing the problem or, even more, loss of data (i.e. files deleted before they were archived). Which is clear operational risk.

    Of course, some people, prominently among them incompetent managers, never heard of operational risk and just do not care.

  • Drasha (unregistered) in reply to John Muller
    John Muller:
    C#...

    Sometimes a simple bit of code needs a comment.

     // Add one to x;
     while ((r = ((x ^ n) & ~(c ^= ((n <<= 1) >> 2)))) < x);
                
    

    Hats off to you dear sir, you have truly made my day... Bravo!

  • Rocketeer (unregistered)

    Hmm, a horrible kludge of different languages mangled together? I've seen this pattern before (although not for the same task) - heck, I've used this pattern before!

    To play Devil's Advocate, and offer a plausible (and almost justifiable) explanation...

    Manager: Dave, I want you to add a function to automatically compress all the files for storage - the customer is complaining that the directories are getting too big to manage. Dave: Um, okay - it'll take a while though, I've never done compression before in C/C++/C# Manager: Oh, that's okay - just put the framework in place. Rob knows how to do compression, he'll write oyu a function. Dave: Okay, cool... I didn't realise Rob knew C!

    ... Three days later

    Manager: Where's that compression function?! Didn't Rob send you the code? Dave: Well, yes... but it's in VB Script. I'm trying to work out how to do the same in C... Manager: No time - just make your C program call the VB script. Dave: Uh, okay, I guess

    ... The next day

    Manager: Dave, what's this about distributing an extra file? The program's supposed to be self-contained. Dave: Well, we had to call Rob's VB Script Manager: No, no, no - can't you generate it on the fly or something? Dave: Sigh... all right...

    I can't remember what I was actually promised when this happened to me - I can remember though that what I actually received was in the wrong language and only worked in one specific case. I spent three days waiting for it, when I could just as easily been writing my own solution... lesson learned!

  • (cs) in reply to Smash King
    Smash King:
    Name changed to provide anonymization:
    Anon:
    Anon:
    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.

    Or, repeatedly zip the same file until you reach the singularity of the 1 bit file.

    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.

    -[Name removed to protect the guilty]

    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?

    I'm suspecting it happened sometime around the second he exited the womb, myself.

  • (cs) in reply to Lego
    Lego:
    Sorry, my mistake! I thought, for a moment, that I was qualified to attempt intelligent discussion in this forum.

    Silly me.

    -Name removed to protect the guilty

    FTFY.

  • crapula (unregistered) in reply to halcyon1234
    halcyon1234:
    Anon:
    Anon:
    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.

    Or, repeatedly zip the same file until you reach the singularity of the 1 bit file.

    I've been doing that for a while now. I think the process is almost done.

    1 <== The entire Internet.

    the good think about that is that i have made the unzip for that:

    internet = null; if( 1 ){ for(i=0.0.0.0; i<255.255.255.255; i++){ internet += wget(i); } } return internet;

  • Joe Scylla (unregistered)
    <?php echo eval("\$str = \"Not the first time i saw Matryoshka code...\";return \"<script type=\\\"text/javascript\\\">document.write('\" . \$str. \"');</script>\";"); ?>
  • Remember the IBM 1130? (unregistered) in reply to Anon

    But, see, you didn't follow the rule set down by cod3_complete ("why", not "what"):

    x = x + 1 // because x needs to have 1 added to it

    TFIFY

  • GlowingOrb (unregistered) in reply to halcyon1234
    halcyon1234:

    I've been doing that for a while now. I think the process is almost done.

    1 <== The entire Internet.

    That's a valid approach. However, I don't want to be the one, who has to decompress it.

  • anonymouse (unregistered) in reply to halcyon1234

    0 <== Oh man, my copy is corrupted.

  • mgb (unregistered) in reply to Anon
    Anon:
    Light switch on = universe exists Light switch off = ...well....you don't want to know what happens when I turn the lights off!
    It will instantly disappear and be replaced by something even more bizarre and inexplicable?
  • vp (unregistered) in reply to Anonymous

    Funny how you stay anonymous while posting.

    (just in case someone recognize you and post your code here...)

  • The real Matryoshka Doll zipfile: (unregistered)

    As seen over on reddit:

    http://www.reddit.com/r/programming/comments/78ee5/a_zip_file_quine/

    I suppose I must also include some text to prove I'm not a spambot? Anyway, it's neat stuff.

  • Anominated (unregistered)

    Can't believe no one even talked about the possible code injection (if the parameters come directly from the user):

    CreateZipFromFolder(CString m_outfile, CString outfolder)
    {
        CString m_outputfilename = m_outfile;
        ...
        fprintf(fp,"%s",p);
        fprintf(fp,"%s",m_outputfilename);
        fprintf(fp,"%s \n",p);
        ...
    }
    

    If m_outfile contains some VBScript code like:

    ";
    DeleteAllYourFiles;
    "

    Then it will be fun!

  • (cs) in reply to Jeesh
    Jeesh:
    <clue> My questions: why to send this one to thedailywtf in the first place? And even more the question to Alex: what is really the WTF? Comma in wrong place, wrong indentation or something more catastrophic in horizon? The code is beautiful hack when management says that no 3rd party software allowed. MS full stop.

    As a teaser to the original poster and to the others : how you will implement the same functionality?

    • in Windows
    • not using any 3rd party tools
    • implementing it in 120 minutes (above is just assumption because part of the code is cut and paste; sorry lads)

    And please put the timer on and let me know.

    </clue>

    -- Jeesh - I am getting old.

    Firstly: let's be clear here: the WTF here is that the code is generating a VBScript file from C++. The VBScript code is inline. Why is that a problem?

    1. The VBScript code could just be pre-made, and pull the file paths from command-line parameters, thus avoiding the need to write it on the fly and not having to worry about temp files.
    2. Everything that VBScript code does can be done from C++, Win32 API, and MFC (all of which are used in the C++ part of the code). a) Writing the blank ZIP: fopen/fwrite and you're done. The exact string would be simply: "PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" (only 17 NULs there, C++ will include the 18th). Note: you can't use fprintf for this, have to use fwrite(). b) Calling the CopyHere function: it's not a VBS-specific function - it's a part of the Shell.Application COM object the VBScript code accesses. C++ can access COM objects just as good as VBScript (if not better in many cases, although no pretty object.method syntax in some cases), so it is just as capable of getting to the CopyHere function utilized. VC++ provides a simple: #import progid:Shell.Application (for example) to get definitions for you to use obj->CopyHere(...); or you can use direct IDispatch calls. Not even yet considering the possibility that compression/"user-like" file copy could be available through direct shell calls rather than via COM objects.
    3. If you want syntax wtfery, the use of RESID_30. For what has to be a double quote based on its use in the generate VBScript. Instead of ... " .

    Sadly I don't have time right now while posting this to actually attempt the "120 minute solution", but will probably do it if anything other than just for the hell of it later.

  • Chris (unregistered) in reply to Alan

    That... or use InfoZip!

  • martian kyo (unregistered)

    it's funny, code like this usually needs to 'the how' comments But people usually comment stuff like a msgbox call

  • oksupra.com (unregistered)

    Supra shoes are so popular all over the world. Whatever you take on Supra being in the Supra Skytop Shoes market. Now Supra Strapped Shoes also very popular attention. It is nice that they actually took the time to make Supra Skate Shoes that work well. Supra shoes is a brand that has been inspired, designed and marketed by passionate individuals. We have brought to you the fullest selection of Supra footwear at cheapest price. Overload Skateshop carries a wide range of Supra Shoes to fit your 9-stair kickflips.

  • oksupra.com (unregistered)

    Supra shoes are so popular all over the world. Whatever you take on Supra being in the Supra Skytop Shoes market. Now Supra Strapped Shoes also very popular attention. It is nice that they actually took the time to make Supra Skate Shoes that work well. Supra shoes is a brand that has been inspired, designed and marketed by passionate individuals. We have brought to you the fullest selection of Supra footwear at cheapest price.

Leave a comment on “Zipping Files - The Matryoshka Doll Way”

Log In or post as a guest

Replying to comment #:

« Return to Article