Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
221 | ligi | 1 | /*************************************************************** |
2 | * |
||
3 | * File Access of DUBwise |
||
4 | * |
||
5 | * Author: Marcus -LiGi- Bueschleb |
||
6 | * Mailto: LiGi @at@ LiGi DOTT de |
||
7 | * |
||
8 | ***************************************************************/ |
||
9 | |||
10 | //#if fileapi=="on" |
||
11 | import javax.microedition.io.*; |
||
12 | import javax.microedition.midlet.*; |
||
13 | import javax.microedition.io.file.*; |
||
14 | |||
15 | import java.io.*; |
||
16 | import java.util.*; |
||
17 | |||
18 | |||
19 | public class DUBwiseFileAccess |
||
20 | { |
||
21 | public final static int MAX_FILELIST_LENGTH=100; |
||
22 | public final static int MAX_PATH_DEPTH=10; |
||
23 | |||
24 | byte act_path_depth=0; |
||
25 | String[] act_path_arr; |
||
26 | |||
27 | |||
28 | public String act_path() |
||
29 | { |
||
30 | String res=""; |
||
31 | for (int i=0;i<act_path_depth;i++) |
||
32 | res+=act_path_arr[i]; |
||
33 | return res; |
||
34 | } |
||
35 | |||
36 | String[] file_list; |
||
37 | int file_list_length=0; |
||
38 | |||
39 | |||
40 | DUBwiseCanvas canvas ; |
||
41 | public DUBwiseFileAccess(DUBwiseCanvas _canvas ) |
||
42 | { |
||
43 | canvas=_canvas; |
||
44 | file_list= new String[MAX_FILELIST_LENGTH]; |
||
45 | act_path_arr=new String[MAX_PATH_DEPTH]; |
||
46 | } |
||
47 | |||
48 | public void fire() |
||
49 | { |
||
50 | |||
51 | if ((canvas.act_menu_select==0)&&(act_path_depth!=0)) |
||
52 | { |
||
53 | act_path_depth--; |
||
54 | //act_path=act_path.substring(0,act_path.substring(0,act_path.length()-2).indexOf('/') ); |
||
55 | |||
56 | //act_path=last_path; |
||
57 | } |
||
58 | else |
||
59 | { |
||
60 | //last_path=act_path; |
||
61 | if (act_path_depth==0) |
||
62 | act_path_arr[act_path_depth++]=file_list[canvas.act_menu_select]; |
||
63 | else |
||
64 | act_path_arr[act_path_depth++]=file_list[canvas.act_menu_select-1]; |
||
65 | } |
||
66 | canvas.act_menu_select=0; |
||
67 | //chg_state(STATEID_FILEOPEN); |
||
68 | trigger(); |
||
69 | } |
||
70 | |||
71 | |||
72 | public void trigger() |
||
73 | { |
||
74 | if (act_path_depth==0) |
||
75 | { |
||
76 | Enumeration drives = FileSystemRegistry.listRoots(); |
||
77 | int tmp_i=0; |
||
78 | while(drives.hasMoreElements()) |
||
79 | { |
||
80 | file_list[tmp_i]= (String) drives.nextElement(); |
||
81 | tmp_i++; |
||
82 | |||
83 | if (MAX_FILELIST_LENGTH<tmp_i) |
||
84 | break; |
||
85 | } |
||
86 | |||
87 | file_list_length=tmp_i; |
||
88 | |||
89 | String[] menu_items=new String[tmp_i]; |
||
90 | // lcd_lines=new String[tmp_i]; |
||
91 | |||
92 | |||
93 | for(tmp_i=0;tmp_i<file_list_length;tmp_i++) |
||
94 | menu_items[tmp_i]=file_list[tmp_i]; |
||
95 | |||
96 | canvas.setup_menu(menu_items,null); |
||
97 | |||
98 | } |
||
99 | else |
||
100 | { |
||
101 | |||
102 | try { |
||
103 | FileConnection fc = (FileConnection) Connector.open("file:///"+act_path()); |
||
104 | Enumeration filelist = fc.list("*", true); |
||
105 | int tmp_i=0; |
||
106 | while(filelist.hasMoreElements()) { |
||
107 | file_list[tmp_i] = (String) filelist.nextElement(); |
||
108 | tmp_i++; |
||
109 | /* fc = (FileConnection) |
||
110 | Connector.open("file:///CFCard/" + fileName); |
||
111 | if(fc.isDirectory()) { |
||
112 | System.out.println("\tDirectory Name: " + fileName); |
||
113 | } else { |
||
114 | System.out.println |
||
115 | ("\tFile Name: " + fileName + |
||
116 | "\tSize: "+fc.fileSize()); |
||
117 | }*/ |
||
118 | |||
119 | } |
||
120 | |||
121 | String[] menu_items=new String[tmp_i+1]; |
||
122 | // lcd_lines=new String[tmp_i+1]; |
||
123 | file_list_length=tmp_i+1; |
||
124 | |||
125 | menu_items[0]=".."; |
||
126 | for(tmp_i=1;tmp_i<file_list_length;tmp_i++) |
||
127 | menu_items[tmp_i]=file_list[tmp_i-1]; |
||
128 | |||
129 | canvas.setup_menu(menu_items,null); |
||
130 | fc.close(); |
||
131 | } catch (IOException ioe) { |
||
132 | System.out.println(ioe.getMessage()); |
||
133 | } |
||
134 | } |
||
135 | |||
136 | |||
137 | } |
||
138 | } |
||
139 | //#endif |