summaryrefslogtreecommitdiff
path: root/songdbj/SongDB.java
blob: 4b7f2aae03f71e8c6da28e10f12b78751a1b9169 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.io.*;
import java.lang.reflect.Array;

public class SongDB { 
	
	public static final void main(String[] args) {		
		TagDatabase td = TagDatabase.getInstance();
		File tdfile = new File("rockbox.tagdb");
	//	RuntimeDatabase rd = RuntimeDatabase.getInstance();
    int i = 0, j;
    String arg,path = null;
		
    while (i < args.length) {
      arg = args[i++];
      if (arg.equals("--dirisnotalbumname")) {
       	 td.dirisalbumname=false;
      }
      else if(arg.equals("--dirisalbum")) {
      	td.dirisalbum=true;
      }
      else if(arg.equals("--dontshowduplicates")) {
      	td.showduplicates=false;
      }
      else if(arg.equals("--strip")) {
        if (i < args.length)
          td.strip = args[i++];
        else {
          System.err.println("--strip requires a path");
          System.exit(0);
        }
      }
      else if(arg.equals("--add")) {
        if (i < args.length)
          td.add = args[i++];
        else {
          System.err.println("--add requires a path");
          System.exit(0);
        }
      }
      else {
      	if(path!=null) {
          System.err.println("you can't specify more than one path!");
          System.exit(0);
        }
      	path = arg;
      }
    }
    if (i != args.length||path==null) {
			System.out.println("Usage: SongDB [--showduplicates] [--strip <directory>] [--add <directory>] [--dirisnotalbumname] [--dirisalbum] <directory>");
			return;
		}
		if(tdfile.exists()&&!tdfile.canWrite()) {
			System.out.println("rockbox.tagdb is not writable.");
			return;
		}
		try {
			tdfile.createNewFile();
		}
		catch(Exception e) {
			System.out.println("Error while trying to create rockbox.tagdb: "+e.getMessage());
			return;
		}
		td.add(new File(path));
		try {
			td.prepareWrite();
		//	rd.prepareWrite();
			td.writeDatabase(new File("rockbox.tagdb"));
		//	rd.writeDatabase(new File("rockbox.rundb"));
		}
		catch(IOException e) {
			System.out.println(e);
		}
	}
}