Rev 221 | Details | Compare with Previous | 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 | |||
382 | ligi | 28 | public boolean dirty=true; |
29 | |||
221 | ligi | 30 | public String act_path() |
31 | { |
||
32 | String res=""; |
||
33 | for (int i=0;i<act_path_depth;i++) |
||
34 | res+=act_path_arr[i]; |
||
35 | return res; |
||
36 | } |
||
382 | ligi | 37 | |
38 | public void refresh_if_dirty() |
||
39 | { |
||
40 | if (dirty) trigger(); |
||
41 | dirty=false; |
||
42 | } |
||
221 | ligi | 43 | |
44 | String[] file_list; |
||
45 | int file_list_length=0; |
||
46 | |||
47 | |||
48 | DUBwiseCanvas canvas ; |
||
49 | public DUBwiseFileAccess(DUBwiseCanvas _canvas ) |
||
50 | { |
||
51 | canvas=_canvas; |
||
52 | file_list= new String[MAX_FILELIST_LENGTH]; |
||
53 | act_path_arr=new String[MAX_PATH_DEPTH]; |
||
54 | } |
||
55 | |||
56 | public void fire() |
||
57 | { |
||
58 | |||
59 | if ((canvas.act_menu_select==0)&&(act_path_depth!=0)) |
||
60 | { |
||
61 | act_path_depth--; |
||
62 | //act_path=act_path.substring(0,act_path.substring(0,act_path.length()-2).indexOf('/') ); |
||
63 | |||
64 | //act_path=last_path; |
||
65 | } |
||
66 | else |
||
67 | { |
||
68 | //last_path=act_path; |
||
69 | if (act_path_depth==0) |
||
70 | act_path_arr[act_path_depth++]=file_list[canvas.act_menu_select]; |
||
71 | else |
||
72 | act_path_arr[act_path_depth++]=file_list[canvas.act_menu_select-1]; |
||
73 | } |
||
74 | canvas.act_menu_select=0; |
||
75 | //chg_state(STATEID_FILEOPEN); |
||
382 | ligi | 76 | dirty=true; |
221 | ligi | 77 | } |
78 | |||
79 | |||
80 | public void trigger() |
||
81 | { |
||
82 | if (act_path_depth==0) |
||
83 | { |
||
84 | Enumeration drives = FileSystemRegistry.listRoots(); |
||
85 | int tmp_i=0; |
||
86 | while(drives.hasMoreElements()) |
||
87 | { |
||
88 | file_list[tmp_i]= (String) drives.nextElement(); |
||
89 | tmp_i++; |
||
90 | |||
91 | if (MAX_FILELIST_LENGTH<tmp_i) |
||
92 | break; |
||
93 | } |
||
94 | |||
95 | file_list_length=tmp_i; |
||
96 | |||
97 | String[] menu_items=new String[tmp_i]; |
||
98 | // lcd_lines=new String[tmp_i]; |
||
99 | |||
100 | |||
101 | for(tmp_i=0;tmp_i<file_list_length;tmp_i++) |
||
102 | menu_items[tmp_i]=file_list[tmp_i]; |
||
103 | |||
104 | canvas.setup_menu(menu_items,null); |
||
105 | |||
106 | } |
||
107 | else |
||
108 | { |
||
109 | |||
110 | try { |
||
382 | ligi | 111 | FileConnection fc = (FileConnection) Connector.open("file:///"+act_path()+"DUBwise"); |
112 | // Enumeration filelist = fc.list("*", true); |
||
113 | fc.mkdir(); |
||
114 | Enumeration filelist = fc.list();//"*", true); |
||
221 | ligi | 115 | int tmp_i=0; |
382 | ligi | 116 | while(filelist.hasMoreElements()) { |
117 | file_list[tmp_i] = (String) filelist.nextElement(); |
||
118 | tmp_i++; |
||
221 | ligi | 119 | /* fc = (FileConnection) |
120 | Connector.open("file:///CFCard/" + fileName); |
||
121 | if(fc.isDirectory()) { |
||
122 | System.out.println("\tDirectory Name: " + fileName); |
||
123 | } else { |
||
124 | System.out.println |
||
125 | ("\tFile Name: " + fileName + |
||
126 | "\tSize: "+fc.fileSize()); |
||
127 | }*/ |
||
128 | |||
129 | } |
||
130 | |||
131 | String[] menu_items=new String[tmp_i+1]; |
||
132 | // lcd_lines=new String[tmp_i+1]; |
||
133 | file_list_length=tmp_i+1; |
||
134 | |||
135 | menu_items[0]=".."; |
||
136 | for(tmp_i=1;tmp_i<file_list_length;tmp_i++) |
||
137 | menu_items[tmp_i]=file_list[tmp_i-1]; |
||
138 | |||
139 | canvas.setup_menu(menu_items,null); |
||
140 | fc.close(); |
||
141 | } catch (IOException ioe) { |
||
142 | System.out.println(ioe.getMessage()); |
||
143 | } |
||
144 | } |
||
145 | |||
146 | |||
147 | } |
||
148 | } |
||
149 | //#endif |