Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gtk;
- using Gee;
- // class FileInfoCollection2 - keeps a collection of File2 objects
- public class FileInfoCollection2 : GLib.Object
- {
- Gee.ArrayList<File2> innerList;
- public FileInfoCollection2(){
- innerList = new Gee.ArrayList<File2>();
- }
- public void add(FileInfo fileinfo){
- innerList.add(new File2(fileinfo));
- }
- public int length(){
- return innerList.size;
- }
- public File2 getItem(int i){
- return innerList.get(i);
- }
- public void SortByName(){
- innerList.sort();
- }
- }
- // class File - wraps a GLib.FileInfo object
- public class File2 : GLib.Object, Comparable<File2>
- {
- private FileInfo f;
- public File2(FileInfo file){
- f = file;
- }
- public string get_name(){
- return f.get_name();
- }
- public int compare_to (File2 f ){
- var a = f.get_name();
- var b = this.get_name();
- return strcmp(a,b);
- }
- }
- // App - gets a bunch of files from disk
- public class App {
- public void* sync_list_directory(string dir) {
- try {
- var directory = File.new_for_path (dir);
- var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
- FileInfo file_info;
- FileInfoCollection2 coll = new FileInfoCollection2();
- while ((file_info = enumerator.next_file (null)) != null) {
- coll.add(file_info);
- }
- coll.SortByName(); // This causes crash. Comment it out and program will not crash.
- for (var i=0; i<coll.length();i++){
- stdout.printf("[%d] - %s\n",i, coll.getItem(i).get_name());
- }
- }
- catch (Error e){
- stderr.printf ("Error: %s\n", e.message);
- }
- return null;
- }
- }
- // Entry point
- static int main (string[] args)
- {
- var app = new App();
- app.sync_list_directory("/home/chriniss/");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement