Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

LennyLen

Member Since 20 Apr 2010
Offline Last Active Today, 12:11 PM
*----

Posts I've Made

In Topic: first game project EVER

Today, 08:58 AM

 

 

... and the thread has a new "biggest WTF".

 
Digital Woe is just the latest incarnation of a guy who was recently banned (as far as I can tell for posting habits).  It looks like he hasn't changed.

 


The funniest part, is the guy used goof prog as his yahoo in his profile. kindof an idiot move to use the same email address that your old account is based on.

 

 

Yup.  That's how I recognized him.


In Topic: first game project EVER

Yesterday, 08:32 PM


... and the thread has a new "biggest WTF".

 

Digital Woe is just the latest incarnation of a guy who was recently banned (as far as I can tell for posting habits).  It looks like he hasn't changed.


In Topic: Help split simple string in c

Yesterday, 08:27 PM


I think should be easy since I know the line from file can be at most 7 characters, and in above format, so I don't need to do any other handling.

 

Even when you are certain that input will be correct, it's best to assume it may not be and do some checking.


In Topic: Violent vs Non Violent Protests

Yesterday, 08:19 PM


Rioters burning busses, buildings, and other property is wrong. It doesn't matter if that property belonged to one individual or belonged to the public. Destruction of property is an actual crime and should be punished

 

Not to mention the fact that you're likely to kill innocent people by setting large objects on fire. 


In Topic: Back to the grindstone

Yesterday, 09:36 AM

@OP: Post some ugly code for us to mock, dangnabbit!

 

 

Here's some ugly C# code I wrote this morning:



using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]

        public static extern int GetShortPathName(

                 [MarshalAs(UnmanagedType.LPTStr)]

                   string path,

                 [MarshalAs(UnmanagedType.LPTStr)]

                   StringBuilder shortPath,

                 int shortPathLength

                 );

        static void Main(string[] args)
        {
            if (File.Exists("playlist"))
            {
                File.Delete("playlist");
            }
            FileStream writetext = File.Create("playlist");
            DirSearch(writetext, "C:\\music");
            writetext.Close();
        }

        static void DirSearch(FileStream FS, string sDir)
        {
            try
            {
                foreach (string d in Directory.GetDirectories(sDir))
                {
                    foreach (string f in Directory.GetFiles(d))
                    {
                        string temp = f.Substring(f.Length - Math.Min(4, f.Length));
                        if (temp.ToUpper() == ".MP3")
                        {
                            StringBuilder shortPath = new StringBuilder(255);
                            GetShortPathName(f, shortPath, shortPath.Capacity);
                            FS.WriteByte((byte)(shortPath.Length + 17));
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)176);
                            FS.WriteByte((byte)(shortPath.Length - 12));
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)12);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            FS.WriteByte((byte)0);
                            AddText(FS, (shortPath.ToString()).ToUpper());
                            FS.WriteByte((byte)10);
                        }
                    }
                    DirSearch(FS, d);
                }
            }
            catch (System.Exception excpt)
            {
                Console.WriteLine(excpt.Message);
            }
        }

        private static void AddText(FileStream fs, string value)
        {
            byte[] info = new UTF8Encoding(true).GetBytes(value);
            fs.Write(info, 0, info.Length);
        }
    }
}

A bit of backstory: The CD changer we use in the restaurant I manage is dying, so I purchased us a cheap MP3 player.  It works well enough, but it only has two methods of choosing tracks - either from the complete library or from a user defined playlist (of which their are five slots).  Since there is some music on it intended for use later on Friday/Saturday nights that isn't really suitable to play at lunch, playing from the entire library isn't good enough, which leaves using the playlists.

 

The playlist functionality is atrocious however, you can't add entire albums or directories. Each song you want on the playlist must be loaded individually and then added manually to the list.  And since I'd put about 6Gb of music on it, that was a LOT of songs to add one at a time.  So I poked around on the player's filesystem and managed to find its playlist files.  The format was easy to figure out.  Each record has a 16 byte header, followed by the filename(which is stored in 8.3 format).  The first byte of the header is the length of the record (including the header itself).  The fifth byte was always the length - 29 (I have no idea why), and every other byte of the header was the same for every record.

 

Discovering all that, I decided it would be a LOT faster to write a program to generate the playlist files than it would be to create them manually.  And that is whatthe code above does.  I created a directory on the C: drive called music (as that is where the MP3s are stored on the device), and for each playlist I want, I just put the tracks I want in the music directory and then run the program.

 

I'm not overly familiar with C#.  I used it briefly about three years ago and haven't used it since (though I really did enjoy using it back then as I found it very easy to develop with C#/.net).  I used it for this task though as it can do the filename conversion in a few lines of code. It would have taken me a lot longer to code the same functionality using plain C.  I didn't care too much if it was a quick hack as it's purely for my own use (though I am considering writing a better version with a GUI for selecting which tracks to add to the playlist.  

 

The main thing was that I needed something very quickly (I wanted it done before I left for work), and it took me very little time to refresh myself with C# and write the code.  It actually took less time to write it than it did to download VS Express.

 

The best part is: The playlists I fabricated worked perfectly on the player first time. Yay!


PARTNERS