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