4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "arraylist.h"
26 #include "bcwindowbase.inc"
33 FileItem(char *path, char *name, int is_dir,
34 int64_t size, int month, int day, int year,
35 int64_t calendar_time, int item_no=-1);
38 int set_path(char *path);
39 int set_name(char *name);
41 const char* get_path();
42 const char* get_name();
52 int64_t calendar_time;
59 // sets the working directory to the user
61 virtual ~FileSystem();
63 // Load the new directory and change current_dir to it.
64 // This does not complete the dir path.
65 // If any of the files failed to stat, it returns nonzero.
66 int scan_directory(const char*);
67 int update(const char *new_dir = 0);
70 // Complete the path in the string and change to the directory in the string.
71 // Does not change new_dir
72 // update - causes the directory to be loaded
73 int change_dir(const char *new_dir, int update = 1);
74 // Set the current_dir to something without completing the path.
75 int set_current_dir(const char *new_dir);
78 char *get_current_dir();
79 // Syntax of filter is
80 // single filter without [].
81 // multiple filters enclosed in [].
82 int set_filter(const char *new_filter);
83 int set_show_all(); // show hidden files
84 int set_want_directory();
85 int set_sort_order(int value);
86 int set_sort_field(int field);
87 int create_dir(const char *new_dir_); // create a new directory
88 int complete_path(char *filename); // use the filename and the current_dir to create a complete filename
89 // return 1 if the text is a directory
90 int is_dir(const char *new_dir_);
91 int extract_dir(char *out, const char *in); // extract the directory from the path
92 int extract_name(char *out, const char *in, int test_dir = 1); // extract the name from the path
93 int join_names(char *out, const char *dir_in, const char *name_in); // combine a directory and filename
94 static int64_t get_date(const char *path); // get the date of the filename modification
95 static void set_date(const char *path, int64_t value); // set the date of the file
96 static int64_t get_size(char *filename); // Get the number of bytes in the file.
97 int add_end_slash(char *new_dir);
99 FileItem* get_entry(int entry);
100 int number_of(FileItem *item);
102 int parse_tildas(char *new_dir); // expand tildas
103 int parse_directories(char *new_dir); // add directories
104 int parse_dots(char *new_dir); // move up directory tree after expanding tildas
105 static char *basepath(const char *path); // collapse ".", "..", "//" elements
107 // Alphabetize all the directories and files. By default
108 // directories come first.
111 // Array of files and directories in the directory pointed to by current_dir.
112 // Directories are first.
113 ArrayList<FileItem*> dir_list;
115 // Sorting order and sorting field. These are identical in BC_ListBox.
122 // Match column definitions in BC_FileBox.
132 int sort_table(ArrayList<FileItem*> *dir_list);
133 static int path_ascending(const void *ptr1, const void *ptr2);
134 static int path_descending(const void *ptr1, const void *ptr2);
135 static int size_ascending(const void *ptr1, const void *ptr2);
136 static int size_descending(const void *ptr1, const void *ptr2);
137 static int date_ascending(const void *ptr1, const void *ptr2);
138 static int date_descending(const void *ptr1, const void *ptr2);
139 static int ext_ascending(const void *ptr1, const void *ptr2);
140 static int ext_descending(const void *ptr1, const void *ptr2);
141 static int dot_reverse_filename(char *out, const char *in);
143 // Combine the directories and files into the master list, directories first.
144 int combine(ArrayList<FileItem*> *dir_list, ArrayList<FileItem*> *file_list);
145 // Return whether or not the string is the root directory.
146 int is_root_dir(char *path);
147 // Whether or not the file passes the current filter.
148 int test_filter(FileItem *file);
149 int reset_parameters();
150 int delete_directory();
152 char filter[BCTEXTLEN]; // what filenames have to end in to get displayed
154 int show_all_files; // shows . files
155 char current_dir[BCTEXTLEN];
156 char string[BCTEXTLEN], string2[BCTEXTLEN];