J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Note: I wish Chrome would fix my spell chek. Sorry everybody =0)

Here's a quick run down of the class.

The properties:

As most of the property names are self-descriptive I'm not going to go through each one, however an addition could be made to the setter methods of each property to prevent changes during compression.

If we add a private member say _Compressing as a boolean to the Zipper Class and set it to true when the compression method is called and false when the process is finished, doing the following to each setter method will prevent potential errors during the compression process due to a user changing a property.

    Private _Source As String
        Public Property SourceURL As String
            Get
                Return _Source
            End Get
            Set(value As String)

                'Add this code
                If _Compressing = True Then Exit Property

                _Source = value

            End Set
        End Property
The Methods

GetSessionLength

        Private Function GetSessionLength() As Int64
            Dim sLen As Int64 = 0
            For Each SessionFile As String In _SessionFiles
                sLen += New FileInfo(SessionFile).Length
                If Cancel = True Then Exit For
            Next
            Return sLen
        End Function

When the Compression method is called all the files\file paths are added to the List(Of String) _SessionFiles. This method simply iterates through each entry and tallys the total length in bytes of all the files to be read and compressed. This information can later be used to report the current progress of the compression process.

IsDir

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Note: I wish Chrome would fix my spell chek. Sorry everybody =0)

Here's a quick run down of the class.

The properties:

As most of the property names are self-descriptive I'm not going to go through each one, however an addition could be made to the setter methods of each property to prevent changes during compression.

If we add a private member say _Compressing as a boolean to the Zipper Class and set it to true when the compression method is called and false when the process is finished, doing the following to each setter method will prevent potential errors during the compression process due to a user changing a property.

    Private _Source As String
    Public Property SourceURL As String
        Get
            Return _Source
        End Get
        Set(value As String)

            'Add this code
            If _Compressing = True Then Exit Property

            _Source = value

        End Set
    End Property
The Methods
GetSessionLength
    Private Function GetSessionLength() As Int64
        Dim sLen As Int64 = 0
        For Each SessionFile As String In _SessionFiles
            sLen += New FileInfo(SessionFile).Length
            If Cancel = True Then Exit For
        Next
        Return sLen
    End Function

When the Compression method is called all the files\file paths are added to the List(Of String) _SessionFiles. This method simply iterates through each entry and tallys the total length in bytes of all the files to be read and compressed. This information can later be used to report the current progress of the compression process.

IsDir

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Ok, so normally all these processes could be complete in one single loop, but for ease of reading I am performing each step seperatly. I also havent included things like ArrayName.Count'-1' I'm assuming you're cool with Array bounds, counts, lengths etc. I hope this helps.

Step 1. Create a 2 dimensional array to hold all the results eg

 ResultsArray(N,2)

N is the number of result sets

    N,0 Holds Team 1 Name
    N,1 Holds Team 2 Name
    N,2 Holds Win

Load the CSV data into this Array

Step 2. Create a 1 Dimensional array to hold all the team names eg TeamList (Do not allow duplicates and do not include the values of "team1" and "team2". Note, if you want to change the table index order e.g. you want them alphabetically, set the values in this array accordingly A-Z etc).

Populate the TeamList array whilst reading the results from the CSV or after by looping through the ResultsArray

Step 3. Once you've done that it's time to put the data in your required table\grid format so create a new 2 dimensional array eg ResultsTable(N,N) where N this time is the number of team names eg TeamList.Count

Time for the old switch-a-roo

Step 4. loop through the sets of data in the ResultsArray and return the Team Name index from the TeamList array and store them accordingly Team1 into X and Team2 into Y e.g

    'Not actual Code Just Visual Representation
    For N = …
happygeek commented: thanks for the effort you are putting in to helping folk +14
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

If you think it will help I can provide you with a textual step by step of my solution. Hopefully you could then translate into java or python... let me know if this will be of use.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Darn, i didn't see the python tag. Sorry. This is vb.net source. Again, apologies. Yeah, keep me informed of your progress. Good luck.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

There are many examples of compressing files in VB.Net. So many of these examples are using third party libraries which is just not neccesarry. People were saying that files and archives exceeding 4Gb couldn't be used... I hate restrictions and decided to "Stick it to Microsoft"

To get a better understanding of Zip files and their contents I set about writing my own Zip file generator from the ground up (Still using Phil Katz's Zip algorythem). Eventually I successfully built my own Zip and ZIP64 archives byte by byte.

I then looked at my work and thought, now I have a grasp of the inner workings of a Zip file (With the PKZip algorythem) let's revist the compresion name space to make sure I wasn't simply wasting my time. It turns out that all I achieved from this project was to get a very solid working knowledge of Zip files, and how to build them internally as these romours about 4Gb limits etc were totally bogus, the Compression namespace converts large files (on the fly) to Zip64 as required. So...

Here is my Compression method, wrapped up nicely in an easy to use class. It uses the .Net4.5 Compression namespace and reads\writes files directly from\to your disk. If you observe your systems performance during compression, No additional memory is used.

I hope this helps a lot of people out in the future.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Ok, I thought I'd play with this. I updated your CSV to check the program, My CSV is like this (Baring in mind, this isn't an effective CSV reader as CSV value may contain commas etc"

Heres My Version of the CSV

team1,team2,win
hawks,celtics,1
hawks,knicks,1
hawks,76ers,0
hawks,lakers,0
hawks,celtics,1
76ers,celtics,1
76ers,lakers,1

And Here's the results printed in the console

               hawks    celtics     knicks      76ers     lakers
     hawks         0         2         1         0         0
   celtics         2         0         0         1         0
    knicks         1         0         0         0         0
     76ers         0         1         0         0         1
    lakers         0         0         0         1         0

You will see a lot of

.PadLeft(10, " ")

This has nothing to do with the program, other then formatting the layout in the console window.

Remeber to import System.IO

Here's the Results Class

    Private Class Results
        Public TeamH As String
        Public TeamA As String
        Public Result As String
    End Class

Here's the main code. Pop it into a button, and you're good to go

        'Open A Stream
        Dim sr As StreamReader = New StreamReader("C:\Users\Jay\Documents\Results.txt")

        Dim ResultsList As List(Of Results) = New List(Of Results)
        Dim TeamList As List(Of String) = New List(Of String)

        Dim rParts(2) As String

        'Read the results
        Do While sr.Peek() >= 0
            rParts = Strings.Split(sr.ReadLine(), ",")
            ResultsList.Add(New Results() With {.TeamH = rParts(0).PadLeft(10, " "), .TeamA = rParts(1).PadLeft(10, " "), .Result = rParts(2)})

            If Not (TeamList.Contains(rParts(0).PadLeft(10, " "))) Then TeamList.Add(rParts(0).PadLeft(10, " "))
            If Not (TeamList.Contains(rParts(1).PadLeft(10, " "))) Then TeamList.Add(rParts(1).PadLeft(10, " "))
        Loop

        'Close The Stream
        sr.Close()

        TeamList.Remove("     team1") …
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

10 Print "Home"
20 Print "Sweet"
30 GOTO 10

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

One morning a woman gets up to find her clothes full of powder. "What's this?" she asks her husband.

"Slim Fast", he replies, "Maybe it could help you lose weight".

The next morning, as the husband is getting dressed, he notices a pile of powder in his underwear.

"What's this then?" he asks his wife.

"miracle grow" replies his wife

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

That was a wee toughie, took a few days. Will sort out that final wee palette glitch, I've already got an idead how to resolve it.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Now tha't some damn fine news... I feel it necassary to quote the out here brothers.."Whoomp! there it is" lol

Please post an image of the in-game graphic at work.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Ok, that was scary. Here is the correct version

Deep Modi commented: Amazing, You are the one that You are giving the great efforts on my projects, AMAZING Talent... GOOD JOB +4
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

\No dont... somethings happening here

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

OMG... it didn't save AHHHHHHHHHHHHHHHHHHHHHHHHHH....

just pulling the recover info, hold on

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Ok, here's 1.1 I'm glad to see the tests work on your game. I have figured out if you use "{" before the inner file name it will render transparent pixels eg "{LOGO" if you just use "LOGO" the entire texture will be solid.

0816e2be0a7a5252d0f904e9eab437a5

I've updated my program with the updated Write method, a transparency chack box, and a palette viewer.

If you want to use your DEEP MODI texture, I figure you need to render the file with transparency unchecked.

Deep Modi commented: Great Job, Salute to you +0
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

No worries, I'll get your filoes and have a play over the next day or so

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Max length you can ignore that, it's the internal file length that's max 16 not the WAD name. TODO: Check image file name (not including .Extension) is <= 16 bytes.

You need both WAD and Edit as my class uses the WAD structures

Please tell me you can follow code to where the images are checked... I've even commented it all for you. If your planning on just using this code without attempting to learn from it, it's kind of dissapointing.

To answer your question... what is the first method the button calls... Editor.CreateWADFile... maybe you should check there.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Ok, this should be it. I uploaded the corect file but I used the same file name so...

Hopefully this should be it. Let me know... and please let's get this solverd lol

Deep Modi commented: Thanks for Attachment +4
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Lol

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Dude ive just written you a bit crunching program... why are you telling me how to set file attributes lol

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Yeah. It's all included in the program. Don't worrt about it bud

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Lol. Thanks, a bit late now as I had to research it but still... useful.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Cant believe its the wrong zip. I'll upload when home.

Pre-check ensures basic things like correct image dimensions, prevent overwrite existing wad, image file exists etc

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Here you go, The complete solution. I've included a sample image with the correct dimensions etc (Multiples of 16) and a sample wad file to extract.

a2a51b2a0f14b66065888044384d6c14

I hope this works for you. Remember... Images dimensions X\Y MUST BE MULTIPLES OF 16. i've included a pre check option to help.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

I've done it.... Just re-factoring and commenting.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

You mean, all you want to do is create a new WAD file, not update an existing one?

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

@Deep Modi... Can you send me your WAD file, the one im using is limited to a 256 colour palette. I want to see what the one you are using is. I refuse to believe a modern game is using 256 colour textures.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

MipMaps.

My interpretation. MipMaps as a collection of pre-rendered images to save processing time (Furher away textures have less pixels to process) and reduce the effects of antialiasing. Each MipMap contains several images from full size down to really small. The 3d enine will select which texture (Images in MipMaps are textures) to apply to the surface depending on the mathmatical distance from the user. In a wad3 file there are four images 1 1\4 1\16 and 1\64. this tells me that the furthest away texture will be resized to a maximum of 1\32 and minimum of 0. When scaling up (getting closer) the software will switch the texture at 1\32 to the second smallest image and resize it from smallest 1\32 passed it's pre-rendered size at 1\16 to an elargement of 1\8 and so on.

http://en.wikipedia.org/wiki/Mipmap

Indexed Images,
Files such as PNG can use and indexed palette, typically up to 256 colours. Unlike a bitmap where the RGB values are written in the byte order they appear, each byte in an indexed PNG holds the index reference to the palette and the color stored within. The palette can be various formats including RGB and ARGB. It seems WAD3 files use this method though much of the PNG's meta headers are removed leaving only the meta values, the image data and the palette information.

Here's more information about indexed images

http://en.wikipedia.org/wiki/Indexed_color

Ok, so over to the code in the zip file

        'Read the …
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

@Deep Modi I thought you would have tried to run the console program, or read my alterations. After you ran my version and you selected your WAD file, the program should have created an "Output" directory in your My Documents folder and extracted all the images. Can you confirm you have the Output folder in your My Documents and can you confirm there are images in the folder. In fact my version should automatically open the Output directory for you.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Mr. M to be fair the console app only reads the data, it doesn't write or rearrange the contents. Though the console program does (should) give all the clues how to achieve this.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

When i get home I'll explain in much more detail what is happening and why you need to stop using the phrase "convert bmp etc to WAD file". Note: a wad file is more like a cab or zip (without the compression) containing textures that are of indexed palette. I know this because i not only researched mips last night but i also inspected the code you ptovided in the zip.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Deep Modi. This isn't my solution. This zip is only your zip converted to WinForms instead of console which you complained about. Listen bud, if you can't understand the code in this program then I'm sorry to point out that thus project may be way over your head... to be polite of course.

I will finish my solution for you which will allow you to overwrite a mip entry based on the original dimensions and palette size.

After that i suggest you study mip files, textures etc like i did last night and try to get a better understanding of what you are trying to do.

Respectfully.
Jay

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Here is the un-edited winform version so you yourself can investigate at the same time. I've included some aditional comments so you can see whats going on. Note: This is only a conversion from console to WinForms so you can play too.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Sorry Deep Modi, I think I missunderstood what you wrote there "Someone more are interested"? Are you saying I am not interested or you don't want my help?

I have converted your given project into winforms... I have figured out how to read the byte information and what's stored where and am currently in the process of 1. Overwriting the original bytes with your new image (pixel and pallette data), and 2. totally rebuilding the wad file with new images.

Also Note, there are 4 MIPs in total per texture in a WAD3 file, th sizes are 1, 1\4, 1\16, and 1\64.

I have to work and I have my own projects, I can't guarantee a week, there's no documentation at all on this.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

Hang in there Deep Modi. I think i've found how to extract contents of a Wad file. Give me time to familiarise myself with it and I'll see what I can do.

Deep Modi commented: Ok, You can take some time, (please target upto this week) +4
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

I think this thread needs flagging as solved... like 18 posts ago

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

I need to apologise to Reverand Jim for my prior outburst, and indeed to the other participants on this thread. It was rude and uncalled for.

@Deep Modi. None of us know the format but aligulsoomro asked for the method to include the use of "-". We cant assume the ID is not 2234-5678... but assume it will be -12345678.

Reverend Jim commented: No problem. +12
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

That's not quite there as a solution Deep Modi, for example IsNumeric(1234-5678-91011) [depending on the ID format] would return false. Also clearing a user input isn't cool beans. It could get increddibly frustrating having to re-type the whole ID each time there was a mistake.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

It would also be important prevent a user from Pasting as all these solutions would be rendered useless

TextBox1.ShortcutsEnabled=False
J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

I'm sorry Reverend Jim... I find the reasnoble alternative solution I provided quite acceptable and much more versatile. Not good coding? I'm sorry sweet heart, did I venture away from your solution. Find a bug in my solution and I'll reconsider the fact you aren't just power tripping. A down vote for an alternative... grow up.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

I find this method really useful. AllowedCodes also holds values for Delete, BackSpace, Home, End, Numeric Keypad Numbers, Standard Numbers etc.

    Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown


        If Not (KeyAllowed(e.KeyCode)) Then e.SuppressKeyPress = True

    End Sub

    Private Function KeyAllowed(Key As System.Windows.Forms.Keys) As Boolean

        Console.WriteLine(Key)

        Dim AllowedCodes() As Byte = {35, 36, 46, 37, 38, 39, 40, 8, 189 _
                                     , 45, 48, 48, 50, 51, 52, 53, 54, 55, 56, 57 _
                                     , 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 109}

        If AllowedCodes.Contains(CInt(Key)) Then
            Return True
        Else
            Return False
        End If

    End Function

I find this way you can ammend your allowed list with the greatest of ease.

J.C. SolvoTerra 109 Eat, Sleep, Code, Repeat Featured Poster

-Hi Bud,

It looks like you are writing all the file bytes at once

strr.Write(file, 0, file.Length)

Typically when you want to generate a progress you need to write chunks of the file eg...

 Using fs As New FileStream(localFile, FileMode.Open, FileAccess.Read, FileShare.None)

                'This is the buffer that will hold the chunks to write
                Dim buffer() As Byte = New Byte(2047) {}

                'Only read 2kb of data per pass (thisfilesize is the length of the local file)
                For offset As Integer = 0 To thisfilesize Step 2048
                    'Let's read 2kb of the local file
                    fs.Read(buffer, 0, buffer.Length)

                    'If the last piece of data is less then 2kb then we'll reduce the chunksize
                    Dim chunkSize As Integer = thisfilesize - offset
                    If chunkSize > 2048 Then chunkSize = 2048

                    'Write the buffer to the remote stream (Buffer Size in this case 2kb)
                    clsStream.Write(buffer, 0, chunkSize)

                    'Update progress if int(percent complete) has changed
                    If prevPerc <> Int((100 / thisfilesize) * (offset + chunkSize)) Then
                        Console.WriteLine(Int((100 / thisfilesize) * (offset + chunkSize)))


                        If boo_RunOnThread = True Then
                            setProgressValue(Int((100 / thisfilesize) * (offset + chunkSize)))
                        Else
                            prg_ProgresBar.Value = Int((100 / thisfilesize) * (offset + chunkSize))

                        End If

                        prevPerc = Int((100 / thisfilesize) * (offset + chunkSize))

                    End If

                Next

            End Using
                Next

I hope this helps. Let me know if you have figured it out already or you need any help at all.