NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 75 76 77 78 79 … 93 Next »
ArrayList

 
  • 0 Vote(s) - 0 Average
ArrayList
darrin75
Offline

Senior Member

Posts: 558
Threads: 103
Joined: Nov 2004
#1
2005-02-24, 08:31 AM
Adding subfolders in a directory to an arraylist, making the folder accessable for new arraylist of files in that subfolder. Code help???Any suggestions? any help??
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#2
2005-02-24, 08:41 AM
the way i did it i used an arraylist called "currentDirectory" everything i added to this arraylist was of type "FileDetails", which was a class that defines a few things, name, absolutepath, size, type.
first i added a parent to the currentDirectory (not in the virtual root, but worry about this stuff later).
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">currentDirectory = new ArrayList();
currentDirectory.Add(new FileDetails("..",location,FileDetails.TYPE_PARENT);
[/QUOTE]
so when the user clicks on the filetdetails of type parent it moves up a dir.

add all the dirs
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">foreach(string dir in Directory.GetDirectories(loc))
currentDirectory.Add(new FileDetails(dir.substring(dir.lastindexOf("\\")+1),dir, FileDetails.TYPE_DIR)
[/QUOTE]

and the files.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">foreach(string file in Directory.GetFiles(loc))
currentDirectory.Add(new FileDetails(dir.substring(dir.lastindexOf("\\")+1),file, FileDetails.TYPE_FILE)
[/QUOTE]

then just check what type the it is when the user clicks on it, if parent move up a dir, if sub, enter dir, if file ...

you might want to keep a integer of the STEP. so STEP=0 is the base dir, moving into a sub folder the step increases by one, moving to parent decreases by one. this way the user cant move beyond the specified original folder.

in the onkeypress method (i think its onkeypress, well onkey something method), just use a check like
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">switch(((FileDetails)currentDirectory[selectedFile]).Type){
case FileDetails.TYPE_PARENT:
//move up a dir
break;

case FileDetails.TYPE_DIR:
//move to dir
break;

case FileDetails.TYPE_FILE:
//open file
break;

}[/QUOTE]

thats basically what i did with the my videos/pics/music/programs plugins.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#3
2005-02-24, 09:36 AM
oh and a sample filedetails class
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">public class FileDetails
public const byte TYPE_PARENT = 0;
public const byte TYPE_FOLDER = 1;
public const byte TYPE_FILE = 2;

private string displayName = "";
private string absolutePath = "";
private byte type;

public FileDetails(string displayName, string absolutePath, byte type){
this.displayName = displayName;
this.absolutePath = absolutePath;
this.type = type;
}

public string DisplayName{
get{
return displayName;
}
}

public string AbsolutePath{
get{
return absolutePath;
}
}

public byte Type{
get{
return type;
}
}

}

[/QUOTE]

if you want to use a graphic for each item you should put it in this method, also possible a dispose method to be called when you change dir eg.

in main class
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">foreach(FileDetails file in currentDirectory)
file.Dispose();
[/QUOTE]

and in FileDetails add a class like
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">public void Dispose(){
if(fileImage != null)
fileImage.Dispose();
fileImage = null;
}[/QUOTE]
where fileImage is just an image ie
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private Image fileImage = null;[/QUOTE]

calling the dispose method will just help with memory management.



jasonf
Offline

Member

Posts: 121
Threads: 7
Joined: Oct 2004
#4
2005-02-24, 12:19 PM
You can also mix types in an arraylist.  That is, maybe the arraylist itself would represent your directory, and if there are subdirectories, then they would be arraylists as well.

We won't have Generics until .NET 2.0, so if you iterate through a mixed collection, you'll need to work with objects and type checking/casting, which makes this approach a little more difficult.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">foreach (object o in myArraylist)
{
  if (o is ArrayList)
  {
     ArrayList ao = o as ArrayList;
     // you can work with ao now
  }
  else if (o is SomeClass)
  {
     SomeClass sco = o as SomeClass;
     // you can work with sco now
  }
  else if (o is SomeValueType)
  {
     SomeValueType svto = (SomeValueType) o;
     // the "as" operator only works with classes
  }
}
[/QUOTE]
JasonF
darrin75
Offline

Senior Member

Posts: 558
Threads: 103
Joined: Nov 2004
#5
2005-03-08, 02:59 AM
Still can't get this to wrok, i guess i am up s creek without a paddle..
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode