2
* Created on 09-dic-2005
4
* TODO To change the template for this generated file go to
5
* Window - Preferences - Java - Code Style - Code Templates
7
package org.herac.tuxguitar.io;
10
import java.io.FileNotFoundException;
12
import org.herac.tuxguitar.io.gp.GPFormatException;
13
import org.herac.tuxguitar.io.tg.TGOutputStream;
14
import org.herac.tuxguitar.song.managers.SongManager;
15
import org.herac.tuxguitar.song.models.Song;
20
* TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates
22
public class TGConverter {
23
private SongManager manager;
24
private String sourceFolder;
25
private String destinationFolder;
27
public TGConverter(String sourceFolder,String destinationFolder){
28
this.manager = new SongManager();
29
this.sourceFolder = sourceFolder;
30
this.destinationFolder = destinationFolder;
33
public void convert(String fileName, String convertFileName) {
35
if(manager.open(fileName)){
36
manager.autoCompleteSilences();
37
System.out.print(convertFileName);
38
new File(new File(convertFileName).getParent()).mkdirs();
39
new TGOutputStream(convertFileName).write(manager.getSong());
40
System.out.println(" [OK] ");
41
}else if (fileName.endsWith(".gp3") || fileName.endsWith(".gp4") || fileName.endsWith(".gp5")) {
42
System.err.println(fileName + " [Unsupported Version]");
44
} catch (FileNotFoundException e) {
45
} catch (GPFormatException e) {
46
System.out.println(convertFileName + " [FAILED] ");
47
System.out.println(" ********** REASON: " + e.getClass().getName() + " ********** ");
50
} catch (Exception e) {
51
System.out.println(convertFileName + " [FAILED] ");
52
System.out.println(" ********** REASON: " + e.getClass().getName() + " ********** ");
55
} catch (OutOfMemoryError e) {
56
System.out.println(convertFileName + " [FAILED] ");
57
System.out.println(" ********** REASON: OutOfMemoryError ********** ");
62
private void process(File folder) {
63
String[] fileNames = folder.list();
64
if(fileNames != null){
65
for (int i = 0; i < fileNames.length; i++) {
66
File file = new File(folder.getPath() + "/" + fileNames[i]);
67
if (file.isDirectory()) {
70
String fileName = file.getAbsolutePath();
71
String convertFileName = getConvertFileName(fileName);
72
convert(fileName, convertFileName);
79
private String getConvertFileName(String path) {
80
String convertPath = (destinationFolder + File.separator +path.substring(sourceFolder.length()));
81
if (convertPath.endsWith(".gp3") || convertPath.endsWith(".gp4") || convertPath.endsWith(".gp5")) {
82
convertPath = convertPath.replaceAll(".gp3", ".tg");
83
convertPath = convertPath.replaceAll(".gp4", ".tg");
84
convertPath = convertPath.replaceAll(".gp5", ".tg");
89
private void writeSong(String fileName, Song song) {
91
new TGOutputStream(fileName).write(song);
92
} catch (FileNotFoundException e) {
98
public static void main(String args[]) {
100
String sourceFolder = args[0];
101
String destinationFolder = args[1];
103
TGConverter converter = new TGConverter(sourceFolder,destinationFolder);
104
File initFolder = new File(sourceFolder);
105
converter.process(initFolder);
112
private static void showHelp(){
113
System.out.println("usage options: [SOURCE FOLDER] [DESTINATION FOLDER]");
b'\\ No newline at end of file'