I love the morning!

Published September 25, 2005
Advertisement
Yeah, mornings rock when I don't have to work.

Wednesday night we had a few tornados in the area, I lost power at about 7pm that night. Nothing big really, a few trees down and the usual. The damage from this was nothing compared to what is currently going on in the gulf. This is really about how I lost my last mornings of joy.

Thursday came around, and I get a call at 7am from my boss, he told me they do not have power yet and I should wait by my phone. I kindly informed him that I have today off, but thanked him for the information. I had to bring my girlfriend into work because bla bla bla early in the morning, at this time there were about 110,000 people in my area w/o power. So 1 out of 3 people are unshowered and looking for coffee, the local gas station was closed and all the ones I drove by were packed full. I was one of the unshowered in need of a pack of smokes and a cup of joe. Not that interisting, I know. Just getting to the point, I left home a little after 7am and arrived home around 10am, it took like 3 hours to get coffee and smokes. I tried to call my family to see if anyone needed help with some cleaning up, didn't get a hold of any of them. I decide to move my computer desk now that it's off, and I can't turn it on. It was fun, and I am happy that I have it where it is now, but I ended up sitting at home with no power until about 5pm. Then I had a serious game session, yay.

Friday morning, I am scheduled to work at 9:30 am, I get another call around 7am telling me the same thing, and to keep my phone near by in case the situation changes. Woohoo! Free day off! I headed off to the super market to get a bag of coffee and something for lunch. I was all comfortable in my new setup, playing around with ADO.NET when I got another call, "we expect to have phones soon, so head in". That call came in at around 10 am, I took 30 minuets to get ready and headed into work for the day. I live near a major highway, and take it to work. I had to cross the highway to get my coffee this morning, and there were no problems, power was on all over the area. My work was on the other side of the river, so I just expected the general area was all back up. Not true, I have not gone south on the highway since going to work on Wednesday, three stop lights were out, so they were reduced to 4-way stops, it only took like 20-25 minuets to go the 4 miles I have to drive to get to work. When I get there, they don't really have power, just partial power. We had some 30 extention cords running around powering up CS workstations. They told us tech-support people that we would not have power to our workstations, that we would have to take notes on paper and just do all the support by memory and asking tons of questions. Good grief! We stood around for about 1 hour before we actually started taking calls. I understand that they want to be back in operation ASAP as a company, if customers can't call in orders as normal, they are losing money. However I also think they should have waited until they could say "ok, we are ready for you, come in now". Tomorrow I will see what time they clocked me in at, I think I should be getting paid for all the time I stood there being ready to goto work. I work until 6:30 pm, one of the other guys who works until 7 asked about breaks for the day, the first thing out of my bosses mouth was "well, we started late today..." and ended with no breaks. We were like WTF?! He came back about a minuet later and said, just make sure you only go one at a time. Thats more like it buddy, thank you! Shit, no breaks after starting only 1 hour late in a 9 hour day (normally minus 30 for lunch, but not today). Since I got there around 11, I was there for 7.5 hours, don't try to tell us we don't get a break. After that the day was pretty much ok, they brought in about 12 pizzas for us, so we didn't have to take a lunch. Because they were down for a day, they asked if some of us would work early/late on Saturday to help take calls, in hopes that customers who didn't get to order Thursday would try to call and our company might be able to pickup some "lost" orders. I work Saturday every week anyway, so I said I would work the extra hours late, because I don't like getting up on Saturday for work, my start time is 1.5 hours sooner than in the week, no way I was going to make it in 1 hour earlier than that.

Saturday we had a generator and air compressor rented, the power company said since we have partial power and other places have none, we were on the bottom of the list. They said it would be 3-5 days (from Thursday) before power would be restored fully. Saturday was actually nothing to complain about really, we had a lot of extra people. I usualy get stuck on CS calls all the time and have to clear thoes before it will send in the TS queue. With all the extra people, it was really slow and I was able to poke around online when I was not on a call. Plus we only stayed 1 hour later than normal, insted of 3. The call volume was not as high as they had anticipated. My friends are having a baby, and I went to my first baby shower after work. It was boring.

Sunday, this is soo much better. In my favorite spot, I have a nice playlist put together, just started drinking my 2nd pot, just finished putting summaries on two classes I made for my GTR File project, I couldn't be happier. I added support for multiple input files when importing to archive, and also a new file button. Infact I just found out about how to add summaries to my code. For all of you who don't know already, if you type three slashes "///" above a function or variable like you are going to comment it, it will fill in the "" tags for you. Makes it nice so you can comment for intellisense.

I doubt many people are interested in this, but here are the two C# classes I made. They are not really finished, I am working on getting the DataBlock to be a MemoryStream insted of a byte array, so keep that in mind if you actually read the code.

GTRFile.cs
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;using ICSharpCode.SharpZipLib;using ICSharpCode.SharpZipLib.Zip.Compression;using ICSharpCode.SharpZipLib.Zip.Compression.Streams;namespace GTR_File{		/*	 * Class: GTRFile	 *		Class for accessing elements stored withing the	 *		.GTR files	 */	/// 	public class GTRFile	{		System.Int64 SIG_HIGH = 0x414d524f544f4d47;		System.Int64 SIG_LOW = 0x0000000000303153;		/// 		/// Number of items in file.		/// 

public int items;
///
/// Length of stored file in bytes.
///
public int FileLength;
///
/// The full path of file.
///
public string sourceFileName;
///
/// true if file has been Parsed, false if not.
///
public bool parsed;

///
/// The index in file of first DataBlock byte.
///
private long DataOffset;
///
/// The ArrayList holding our GTRFileItem collection.
///
private System.Collections.ArrayList ItemArray;
private System.Int64 SigHigh;
private System.Int64 SigLow;

///
/// Constructor.
///
/// Name of file.
/// bool, parse file after open.
///
public GTRFile(string filename, bool parse)
{
ItemArray = new ArrayList();
parsed = false;
sourceFileName = filename;
if(parse)
this.Parse();
}

///
/// Create a new GTRFileItem.
///
/// The new item.
public GTRFileItem NewItem()
{
int item_n;
item_n = ItemArray.Add(new GTRFileItem());
++items;
return (GTRFileItem)ItemArray[item_n];
}

///
/// Get GTRFileItem for index number.
///
/// Zero based index of item.
/// The GTRFileItem for index.
public GTRFileItem GetFileItem(int n)
{
if(n >= items)
return (GTRFileItem)null;
return (GTRFileItem)ItemArray[n];
}

///
/// Reads the header for an existing .GTR file.
///
///
/// The success of the operation.
private bool ReadHeader(System.IO.BinaryReader breader)
{
try
{
if(!CheckSignature(breader))
return false;

items = breader.ReadInt32();
FileLength = breader.ReadInt32();
}
catch (Exception e)
{
MessageBox.Show(e.Message, "GTRFile::ReadHeader()");
}

return true;
}

///
/// Reads the GTRFile Signature from an open binary reader.
///
/// binary reader to read from, expects the reader to be
/// seeked to the begining of the file.
/// true if the signature matches, false if not.
private bool CheckSignature(System.IO.BinaryReader breader)
{
try
{
SigHigh = breader.ReadInt64();
SigLow = breader.ReadInt64();

if(SigHigh == SIG_HIGH && SigLow == SIG_LOW)
return true;

MessageBox.Show("Signature Mismatch!", "GTRFile::CheckSignature()");
return false;
}
catch (Exception e)
{
string strMsg = e.Message;
MessageBox.Show(strMsg,"GTRFile::CheckSignature()");
return false;
}
}

///
/// Parses the GTR file, reads the file index and loads the items into ItemArray.
///
/// The success of the operation.
public bool Parse()
{
System.IO.FileStream infs;
System.IO.BinaryReader breader;

try
{
infs = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open );
breader = new System.IO.BinaryReader(infs);

ReadHeader(breader);

for(int i=0;i {
GTRFileItem titem;
int n = ItemArray.Add(new GTRFileItem());
titem = (GTRFileItem)ItemArray[n];
titem.ReadItem(breader);
}
DataOffset = breader.BaseStream.Position;
for(int i=0;i {
GTRFileItem titem = (GTRFileItem)ItemArray;
long seek_pos = titem.Offset + DataOffset;
breader.BaseStream.Seek(seek_pos,System.IO.SeekOrigin.Begin);
byte[] buff = new byte[titem.Length];
buff = breader.ReadBytes(titem.Length);
titem.StoreDataBlock(buff,titem.Length,true);
//titem.CompressedBlock = true;
titem.CompressionLevel = 1;
}

breader.Close();
parsed = true;
return true;
}
catch (Exception e)
{
string strMsg = e.Message;
MessageBox.Show(strMsg, "GTRFile::Parse()");
return false;
}
//return false;
}

///
/// Get a BinaryReader seeked to selected indexed file.
///

/// Zero based index of item.
/// BinaryReader seeked to position of data in the .GTR file.
public System.IO.BinaryReader GetFileReader(int n)
{
System.IO.FileStream infs = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open);
System.IO.BinaryReader breader = new System.IO.BinaryReader(infs);

GTRFileItem fitem = (GTRFileItem)ItemArray[n];

if(!breader.BaseStream.CanSeek)
{
return (System.IO.BinaryReader)null;
}
breader.BaseStream.Seek( (DataOffset + fitem.Offset) ,System.IO.SeekOrigin.Begin);
return breader;
}

///
/// Write a header for current in-memory file.
///
/// An open BinaryWriter to write to.
public void WriteHeader(System.IO.BinaryWriter bwriter)
{
bwriter.Write(SIG_HIGH);
bwriter.Write(SIG_LOW);
bwriter.Write(items);

int dblocks_sz = 0;
for(int i=0;i dblocks_sz += ((GTRFileItem)ItemArray).Length;

int total_len = 16 + (items * 256) + dblocks_sz;
bwriter.Write(total_len);
}

///
/// Calculates offsets for all items in array.
///

/// Number of offsets calculated.
public int CalculateItemOffsets()
{
int ret = 0;
int run = 0;
for(int i=0;i {
GTRFileItem item = (GTRFileItem)ItemArray;
item.Offset = run;
run += item.Length;

++ret;
}
return ret;
}

///
/// Write index data for GTR file.
///

/// An open BinaryWriter seeked past header.
public void WriteIndex(System.IO.BinaryWriter bwriter)
{
try
{
for(int i=0;i {
GTRFileItem item = (GTRFileItem)ItemArray;
bwriter.Write(item.Type);
bwriter.Write(item.Offset);
bwriter.Write(item.USize);
bwriter.Write(item.Length);
byte[] fn240 = new byte[240];
// no string to byte[] conversion?!
// we have to copy the string into a char[]
// and then convert to byte[].
char[] grr = item.FileName.ToCharArray();
for(int j=0;j fn240[j] = Convert.ToByte(grr[j]);

// fill in remaining with 0x00
// item.FileName.Length will point us to 1+ the last
// byte in the filename in fn240 because it is zero indexed
for(int j = item.FileName.Length;j<240;++j)
fn240[ j ] = (byte)'\0';

bwriter.Write(fn240);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"GTRFile::WriteIndex()");
}
}

///
/// Write DataBlocks from items to file.
///

/// An open BinaryWriter seeked past index.
public void WriteDataBlocks(System.IO.BinaryWriter bwriter)
{
try
{
for(int i=0;i {
GTRFileItem item = (GTRFileItem)ItemArray;
bwriter.Write(item.DataBlock,0,item.Length);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"GTRFile::WriteDataBlocks()");
}
}

///
/// Remove item at index from ItemArray
///

/// Zero based index of item to remove.
public void RemoveItem(int index)
{
if(index >= 0 && index < this.ItemArray.Count)
{
this.ItemArray.RemoveAt(index);
this.items--;
}
}
};

}



GTRFileItem.cs
	/*==========================================================	 * Class: GTRFileItem	 *		Stores local information about each item archived in	 *		the .GTR file.	 ==========================================================*/using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Runtime.InteropServices;using ICSharpCode.SharpZipLib;using ICSharpCode.SharpZipLib.Zip.Compression;using ICSharpCode.SharpZipLib.Zip.Compression.Streams;namespace GTR_File{	public class GTRFileItem	{		public static Int32 GMT = 0x00000011;		public static Int32 BMP = 0x00000012;		public static Int32 TGA = 0x00000014;		public static Int32 DDS = 0x00000237;		/// 		/// Type code for stored file.		/// 

public int Type;
///
/// Data-start offset past end-of-index.
///
public int Offset;
///
/// Uncompressed size of item.
///
public int USize;
///
/// Compressed length of item.
///
public int Length;
///
/// Local filename.
///
public string FileName;
///
/// byte array holding item data.
///
public byte[] DataBlock;
///
/// MemoryStream holding item data.
///
public System.IO.MemoryStream mstrm;

///
/// true if data is currently compressed, false if not.
///
public bool CompressedBlock;
///
/// Compression level used when compressing file.
///
public int CompressionLevel;

///
/// Empty, default constructor.
///
public GTRFileItem()
{
}

///
/// Discover the type code for the given file.
///
/// The filename to process.
/// 32-bit integer file type, 0 for unknown.
public Int32 FindItemType(string filename)
{
int flen = filename.Length;
int dotpos = 1 + filename.LastIndexOf(".");
if( (flen - dotpos) < 3)
{
return 0;
}
char[] buf = new char[3];
filename.CopyTo(dotpos, buf, 0, 3);
string fileext = new string(buf);

if(fileext == "TGA")
return TGA;

else if(fileext == "BMP")
return BMP;

else if(fileext == "DDS")
return DDS;

else if(fileext == "GMT")
return GMT;

else
return 0;
}

///
/// Read item properties from given reader.
///
/// An open, and seeked BinaryReader to read from.
/// The success of the operation.
public bool ReadItem(System.IO.BinaryReader breader)
{
try
{
Type = breader.ReadInt32();
Offset = breader.ReadInt32();
USize = breader.ReadInt32();
Length = breader.ReadInt32();
char[] ctmp = breader.ReadChars(240);
string stmp = new string(ctmp);
int firstz = stmp.IndexOf('\0');
stmp = stmp.Remove(firstz, (stmp.Length - firstz));
FileName = stmp;
return true;
}
catch (Exception e)
{
MessageBox.Show(e.Message,"GTRFileItem::ReadItem");
return false;
}
}

///
/// Store data into items DataBlock and mstrm.
///
/// byte array to read from.
/// number of bytes to read
/// true if data passed is compressed, false if not
public void StoreDataBlock(byte[] indata, int length, bool compressed)
{
this.DataBlock = new byte[length];
this.DataBlock = indata;
this.CompressedBlock = compressed;
this.mstrm = new System.IO.MemoryStream(length);
this.mstrm.Write(indata,0,length);
}

///
/// Decompress DataBlock and mstrm.
///
public void DecompressBlock()
{
if(this.CompressedBlock == false)
return;
try
{
ICSharpCode.SharpZipLib.Zip.Compression.Inflater inflater = new
ICSharpCode.SharpZipLib.Zip.Compression.Inflater(false);

this.mstrm.Seek(0,System.IO.SeekOrigin.Begin);
InflaterInputStream ifStream = new InflaterInputStream(this.mstrm,inflater);

System.IO.MemoryStream iblock = new System.IO.MemoryStream();

byte[] dbuf = new byte[this.USize];

int len = 0;
while(true)
{
int sz = ifStream.Read( dbuf, 0, 4096);
if(sz <= 0)
break;
iblock.Write(dbuf,0,sz);
len += sz;
}

this.mstrm.SetLength(len);
this.mstrm.Write(iblock.ToArray(),0,len);
this.DataBlock = iblock.ToArray();
this.CompressedBlock = false;
this.USize = len;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"GTRFileItem::DecompressBlock");
}
}

///
/// Compress DataBlock with given compression level.
///
/// Level of compression (1-9)
public void CompressBlock(int level)
{
if(this.CompressedBlock == true)
return;
try
{
// record the uncompressed size
this.USize = (int)this.DataBlock.Length;

// Ms is the destination for the deflated stream
System.IO.MemoryStream Ms = new System.IO.MemoryStream();
// deflater initilized with compression level and header flag
ICSharpCode.SharpZipLib.Zip.Compression.Deflater deflater = new Deflater(level,false);
ICSharpCode.SharpZipLib.Zip.Compression.Streams.DeflaterOutputStream Ds = new
DeflaterOutputStream(Ms,deflater);

// write the uncompressed data to the deflater stream
Ds.Write(this.DataBlock,0,(int)this.DataBlock.Length);
Ds.Flush();
Ds.Finish();

// copy compressed data to the block
this.DataBlock = Ms.ToArray();
// resize our objects memory stream
this.mstrm.SetLength(Ms.Length);
// update stream
this.mstrm = Ms;
this.CompressedBlock = true;
this.CompressionLevel = level;
this.Length = (int)Ms.Length;

Ds.Close();
Ms.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"GTRFileItem::CompressBlock");
}
}
};
}



Secrest, out!
Previous Entry Not bad.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Not bad.

1145 views

Zoned out.

1021 views

more

1100 views

Slow down champ.

917 views

I'll be back

879 views

Busy.

1035 views

oh teh noes!!

923 views
Advertisement