1 /*
2  * @(#)Common.java - carries various stuff, the center class
3  *
4  * Copyright (c) 2004-2011 by dvb.matt, All Rights Reserved.
5  *
6  * This file is part of ProjectX, a free Java based demux utility.
7  * By the authors, ProjectX is intended for educational purposes only,
8  * as a non-commercial test project.
9  *
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  *
25  */
26 
27 package net.sourceforge.dvb.projectx.common;
28 
29 import java.awt.GraphicsEnvironment;
30 import java.awt.Color;
31 import java.awt.Rectangle;
32 
33 import java.io.BufferedInputStream;
34 import java.io.BufferedReader;
35 import java.io.ByteArrayOutputStream;
36 import java.io.File;
37 import java.io.IOException;
38 import java.io.InputStreamReader;
39 
40 import java.net.URL;
41 import java.net.URLConnection;
42 
43 import java.util.ArrayList;
44 import java.util.List;
45 import java.util.Arrays;
46 import java.util.Hashtable;
47 import java.util.StringTokenizer;
48 import java.util.Date;
49 import java.util.TimeZone;
50 import java.util.Comparator;
51 
52 import java.text.NumberFormat;
53 
54 import java.io.StringWriter;
55 import java.io.PrintWriter;
56 
57 import java.text.DateFormat;
58 import java.text.SimpleDateFormat;
59 
60 import net.sourceforge.dvb.projectx.audio.AudioFormat;
61 
62 import net.sourceforge.dvb.projectx.parser.CommonParsing;
63 import net.sourceforge.dvb.projectx.parser.Scan;
64 import net.sourceforge.dvb.projectx.parser.MainProcess;
65 
66 import net.sourceforge.dvb.projectx.subtitle.Subpicture;
67 import net.sourceforge.dvb.projectx.subtitle.Teletext;
68 
69 import	net.sourceforge.dvb.projectx.video.MpvDecoder;
70 
71 import net.sourceforge.dvb.projectx.xinput.XInputFile;
72 import net.sourceforge.dvb.projectx.xinput.XInputDirectory;
73 import net.sourceforge.dvb.projectx.xinput.topfield_raw.RawInterface;
74 import net.sourceforge.dvb.projectx.xinput.DirType;
75 
76 import net.sourceforge.dvb.projectx.net.WebInterface;
77 
78 /**
79  *
80  */
81 public final class Common extends Object {
82 
83 	/* main version index */
84 	private static String version_name = "ProjectX 0.91.0.00";
85 	private static String version_date = "31.03.2011";
86 
87 	private static String line_separator = System.getProperty("line.separator");
88 
89 	private static String messagelog = "";
90 
91 	private static int ProcessedCollection = 0;
92 	private static int ActiveCollection = -1;
93 
94 	private static int ProcessedPercent = 0;
95 	private static int ErrorCount = 0;
96 	private static int FileID = 0;
97 
98 	private static boolean showGUI = false;
99 	private static boolean runningCLI = false;
100 	private static boolean runningProcess = false;
101 	private static boolean GlobalDebug = false;
102 	private static boolean TimeLog = false;
103 	private static boolean MaxLog = false;
104 
105 	private static boolean canAccessFtp = true;
106 	private static boolean canAccessRawread = true;
107 	private static boolean canAccessColorTable = true;
108 	private static boolean canAccessSilentAC3 = true;
109 
110 	/** name of the colours table file */
111 	private static final String COLOUR_TABLES_FILENAME = "colours.tbl";
112 
113 	/** name of the ac3 file */
114 	private static final String AC3_FILENAME = "ac3.bin";
115 
116 	/**  */
117 	private static ArrayList subpicture_colormodels = null;
118 
119 	/** list of AC3 frames */
120 	private static List AC3list = new ArrayList();
121 
122 	private static DateFormat time_format_1 = new SimpleDateFormat("HH:mm:ss.SSS");
123 	private static DateFormat time_format_2 = new SimpleDateFormat("HH:mm:ss:SSS");
124 	private static DateFormat time_format_3 = new SimpleDateFormat("dd.MM.yy  HH:mm");
125 	private static DateFormat time_format_4 = new SimpleDateFormat("HH:mm:ss");
126 	private static DateFormat time_format_5 = new SimpleDateFormat("yyyyMMddHHmm");
127 
128 	private static byte temp_byte;
129 
130 	private static Settings settings;
131 
132 	/* status panel */
133 	private static int[] FpsValue = { 0, 0 };
134 	private static long[] Data_Troughput = { 0, 0 };
135 	private static int SplitPart = 0;
136 	private static String StatusString = null;
137 
138 	/* preview autom. buffer */
139 	private static int LastPreviewBitrate = 1875000;
140 
141 	/* linkage to x.swing components */
142 	private static GuiInterface guiInterface = null;
143 
144 	private static Subpicture subpicture = null;
145 
146 	private static Teletext teletext = null;
147 
148 	private static Scan scan = null;
149 
150 	private static MpvDecoder mpvdecoder = null;
151 
152 	private static WebInterface webserver = null;
153 
154 	private static MainProcess mainprocess = null;
155 
156 	private static long ProcessTime = 0;
157 
158 	/**
159 	 * carries all new collection classes
160 	 */
161 	private static List collectionList = new ArrayList();
162 
163 	/**
164 	 *
165 	 */
Common()166 	private Common()
167 	{}
168 
169 	/**
170 	 * save settings, if enabled and no fatal error has occured
171 	 */
exitApplication(int returncode)172 	public static void exitApplication(int returncode)
173 	{
174 		if (returncode == 0 && getSettings().getBooleanProperty(Keys.KEY_SaveSettingsOnExit))
175 			saveSettings();
176 
177 		System.exit(returncode);
178 	}
179 
180 	/**
181 	 *
182 	 */
setSettings()183 	public static void setSettings()
184 	{
185 		setSettings(null);
186 	}
187 
188 	/**
189 	 *
190 	 */
setSettings(String str)191 	public static void setSettings(String str)
192 	{
193 		if (settings != null)
194 			return;
195 
196 		if (str == null)
197 			settings = new Settings();
198 
199 		else
200 			settings = new Settings(str);
201 	}
202 
203 	/**
204 	 *
205 	 */
getSettings()206 	public static Settings getSettings()
207 	{
208 		return settings;
209 	}
210 
211 	/**
212 	 *
213 	 */
saveSettings()214 	public static void saveSettings()
215 	{
216 		saveSettings(null);
217 	}
218 
219 	/**
220 	 *
221 	 */
saveSettings(String str)222 	public static void saveSettings(String str)
223 	{
224 		getSettings().setProperty(Keys.KEY_Language[0], Resource.getChosenLanguage());
225 
226 		getMainFrameBounds();
227 
228 		settings.save(str);
229 	}
230 
231 	/**
232 	 *
233 	 */
init()234 	public static void init()
235 	{
236 		StatusString = Resource.getString("run.status");
237 
238 		scan = new Scan();
239 		subpicture = new Subpicture();
240 		teletext = new Teletext();
241 		mpvdecoder = new MpvDecoder();
242 		subpicture_colormodels = loadColorModels();
243 	}
244 
245 	/**
246 	 *
247 	 */
startWebServer()248 	public static void startWebServer()
249 	{
250 		if (webserver == null)
251 			webserver = new WebInterface();
252 
253 		stopWebServer();
254 
255 		webserver.start();
256 	}
257 
258 	/**
259 	 *
260 	 */
stopWebServer()261 	public static void stopWebServer()
262 	{
263 		if (webserver == null)
264 			return;
265 
266 		webserver.stop();
267 	}
268 
269 	/**
270 	 *
271 	 */
isWebServerOnline()272 	public static boolean isWebServerOnline()
273 	{
274 		if (webserver != null && webserver.isOnline())
275 			return true;
276 
277 		return false;
278 	}
279 
280 	/**
281 	 *
282 	 */
prepareGui(boolean b)283 	public static void prepareGui(boolean b)
284 	{
285 		showGUI = b;
286 
287 		//prepare gui
288 		guiInterface = new GuiInterface(showGUI);
289 
290 		//load gui
291 		if (showGUI())
292 			getGuiInterface().loadGui();
293 	}
294 
295 	/**
296 	 *
297 	 */
getGuiInterface()298 	public static GuiInterface getGuiInterface()
299 	{
300 		return guiInterface;
301 	}
302 
303 	/**
304 	 *
305 	 */
showGUI()306 	public static boolean showGUI()
307 	{
308 		return showGUI;
309 	}
310 
311 	/**
312 	 *
313 	 */
getSubpictureClass()314 	public static Subpicture getSubpictureClass()
315 	{
316 		return subpicture;
317 	}
318 
319 	/**
320 	 *
321 	 */
getTeletextClass()322 	public static Teletext getTeletextClass()
323 	{
324 		return teletext;
325 	}
326 
327 	/**
328 	 *
329 	 */
getScanClass()330 	public static Scan getScanClass()
331 	{
332 		return scan;
333 	}
334 
335 	/**
336 	 *
337 	 */
getMpvDecoderClass()338 	public static MpvDecoder getMpvDecoderClass()
339 	{
340 		return mpvdecoder;
341 	}
342 
343 	/**
344 	 *
345 	 */
startProcess()346 	public static boolean startProcess()
347 	{
348 		boolean b = true;
349 
350 		if (isRunningProcess())
351 			return !b;
352 
353 		if (isCollectionListEmpty())
354 			return !b;
355 
356 		setRunningProcess(b);
357 
358 		CommonParsing.setPvaPidToExtract(-1);
359 
360 		return b;
361 	}
362 
363 	/**
364 	 *
365 	 */
waitingMainProcess()366 	public static boolean waitingMainProcess()
367 	{
368 		return (mainprocess != null ? mainprocess.pause() : false);
369 	}
370 
371 	/**
372 	 *
373 	 */
startMainProcess()374 	public static void startMainProcess()
375 	{
376 		mainprocess = new MainProcess();
377 		mainprocess.start();
378 	}
379 
380 	/**
381 	 *
382 	 */
breakMainProcess()383 	public static void breakMainProcess()
384 	{
385 		if (!isRunningProcess())
386 			return;
387 
388 		setMessage(Resource.getString("golistener.msg.cancelled"), true, 0xE0E0FF);
389 
390 		CommonParsing.setProcessPausing(false);
391 		CommonParsing.setProcessCancelled(true);
392 	}
393 
394 	/**
395 	 *
396 	 */
killMainProcess()397 	public static void killMainProcess()
398 	{
399 		if (!isRunningProcess())
400 			return;
401 
402 		breakMainProcess();
403 
404 		mainprocess.stop();
405 		mainprocess = null;
406 	}
407 
408 	/**
409 	 *
410 	 */
setRunningProcess(boolean b)411 	public static void setRunningProcess(boolean b)
412 	{
413 		runningProcess = b;
414 
415 		TimeLog = getSettings().getBooleanProperty(Keys.KEY_MessagePanel_Msg4);
416 		MaxLog = getSettings().getBooleanProperty(Keys.KEY_MessagePanel_Msg8);
417 		ErrorCount = 0;
418 
419 		if (runningProcess)
420 		{
421 			setMessage(null, true, 0xFFFFFF);
422 
423 			if (getSettings().getBooleanProperty(Keys.KEY_minimizeMainFrame))
424 				showMainFrame(false);
425 
426 			if (getSettings().getBooleanProperty(Keys.KEY_hideProcessWindow))
427 				getGuiInterface().closeLogWindow();
428 		}
429 
430 		else
431 		{
432 			showMainFrame(true);
433 			getGuiInterface().showLogWindow();
434 		}
435 	}
436 
437 	/**
438 	 *
439 	 */
isRunningProcess()440 	public static boolean isRunningProcess()
441 	{
442 		return runningProcess;
443 	}
444 
445 	/**
446 	 *
447 	 */
setRunningCLI(boolean b)448 	public static void setRunningCLI(boolean b)
449 	{
450 		runningCLI = b;
451 	}
452 
453 	/**
454 	 *
455 	 */
isRunningCLI()456 	public static boolean isRunningCLI()
457 	{
458 		return runningCLI;
459 	}
460 
461 
462 	/**
463 	 *
464 	 */
setProcessTime(long val)465 	public static void setProcessTime(long val)
466 	{
467 		ProcessTime = val;
468 	}
469 
470 	/**
471 	 *
472 	 */
getProcessTime()473 	public static long getProcessTime()
474 	{
475 		if (!isRunningProcess() || ProcessTime <= 0)
476 			return 0L;
477 
478 		return (System.currentTimeMillis() - ProcessTime);
479 	}
480 
481 	/**
482 	 *
483 	 */
setGlobalDebug(boolean b)484 	public static void setGlobalDebug(boolean b)
485 	{
486 		GlobalDebug = b;
487 	}
488 
489 	/**
490 	 *
491 	 */
getGlobalDebug()492 	public static boolean getGlobalDebug()
493 	{
494 		return GlobalDebug;
495 	}
496 
497 	/**
498 	 *
499 	 */
getProcessedCollection()500 	public static int getProcessedCollection()
501 	{
502 		return ProcessedCollection;
503 	}
504 
505 	/**
506 	 *
507 	 */
setProcessedCollection(int val)508 	public static void setProcessedCollection(int val)
509 	{
510 		ProcessedCollection = val;
511 	}
512 
513 	/**
514 	 *
515 	 */
getActiveCollection()516 	public static int getActiveCollection()
517 	{
518 		return ActiveCollection;
519 	}
520 
521 	/**
522 	 *
523 	 */
setActiveCollection(int val)524 	public static void setActiveCollection(int val)
525 	{
526 		ActiveCollection = val;
527 	}
528 
529 	/**
530 	 *
531 	 */
getLineSeparator()532 	public static String getLineSeparator()
533 	{
534 		return line_separator;
535 	}
536 
537 	/**
538 	 *
539 	 */
getVersionName()540 	public static String getVersionName()
541 	{
542 		return version_name;
543 	}
544 
545 	/**
546 	 *
547 	 */
getVersionDate()548 	public static String getVersionDate()
549 	{
550 		return version_date;
551 	}
552 
553 	/**
554 	 * Returns the Version information
555 	 *
556 	 * @return String[]
557 	 */
getVersion()558 	public static String[] getVersion()
559 	{
560 		return new String[] {
561 			getVersionName(),
562 			getVersionDate(),
563 			Resource.getString("version.info"),
564 			Resource.getString("version.user") + System.getProperty("user.name")
565 		};
566 	}
567 
568 	/**
569 	 *
570 	 */
getDateAndTime()571 	public static String getDateAndTime()
572 	{
573 		return (DateFormat.getDateInstance(DateFormat.LONG).format(new Date()) + "    " + DateFormat.getTimeInstance(DateFormat.LONG).format(new Date()));
574 	}
575 
576 	/**
577 	 *
578 	 */
formatNumber(long val)579 	public static String formatNumber(long val)
580 	{
581 		return NumberFormat.getInstance().format(val);
582 	}
583 
584 	/**
585 	 * return collection
586 	 */
isCollectionListEmpty()587 	public static boolean isCollectionListEmpty()
588 	{
589 		return collectionList.isEmpty();
590 	}
591 
592 	/**
593 	 * return collectionlist size
594 	 */
getCollectionListSize()595 	public static int getCollectionListSize()
596 	{
597 		return collectionList.size();
598 	}
599 
600 	/**
601 	 * remove collection
602 	 */
removeCollection(int index)603 	public static boolean removeCollection(int index)
604 	{
605 		if (index < 0 || index >= collectionList.size())
606 			return false;
607 
608 		if (getCollection(index).isActive())
609 			return false;
610 
611 		collectionList.remove(index);
612 
613 		return true;
614 	}
615 
616 	/**
617 	 * return collection
618 	 */
getCollection()619 	public static JobCollection getCollection()
620 	{
621 		return getCollection(getActiveCollection());
622 	}
623 
624 	/**
625 	 * return collection
626 	 */
getCollection(int index)627 	public static JobCollection getCollection(int index)
628 	{
629 		if (index < 0 || index >= collectionList.size())
630 			return null;
631 
632 		return (JobCollection) collectionList.get(index);
633 	}
634 
635 	/**
636 	 * if collection doesnt exists, create one
637 	 */
addCollection()638 	public static JobCollection addCollection()
639 	{
640 		return addCollection(true);
641 	}
642 
643 	/**
644 	 * if collection doesnt exists, create one
645 	 */
addCollection(boolean append)646 	public static JobCollection addCollection(boolean append)
647 	{
648 		/**
649 		 * ensure only, that at least one coll exists
650 		 */
651 		if (!append && !collectionList.isEmpty())
652 			return null;
653 
654 		/**
655 		 * create new coll, with current output dir.
656 		 */
657 		return addCollection(new JobCollection(getSettings().getProperty(Keys.KEY_OutputDirectory)));
658 	}
659 
660 	/**
661 	 *
662 	 */
addCollection(JobCollection collection)663 	public static JobCollection addCollection(JobCollection collection)
664 	{
665 		/**
666 		 * add new coll
667 		 */
668 		collectionList.add(collection);
669 
670 		addCollectionAtEnd();
671 
672 		return collection;
673 	}
674 
675 	/**
676 	 * check whether commons-net is available, to prevent malfunctions
677 	 */
checkLibraryAccess()678 	public static String checkLibraryAccess()
679 	{
680 		try {
681 			Class cls = Class.forName("org.apache.commons.net.ftp.FTPClient");
682 
683 			canAccessFtp = true;
684 
685 			return null;
686 		}
687 		catch (Exception exc) {}
688 		catch (Error err) {}
689 
690 		return "\ncommons-net library not accessible! see readme.txt [ii]\nensure the correct location/classpath, related to the executed .jar\n";
691 	}
692 
693 	/**
694 	 *
695 	 */
canAccessFtp()696 	public static boolean canAccessFtp()
697 	{
698 		return canAccessFtp;
699 	}
700 
701 	/**
702 	 *
703 	 */
canAccessRawRead()704 	public static boolean canAccessRawRead()
705 	{
706 		return canAccessRawread;
707 	}
708 
709 	/**
710 	 *
711 	 */
canAccessColorTable()712 	public static boolean canAccessColorTable()
713 	{
714 		return canAccessColorTable;
715 	}
716 
717 	/**
718 	 *
719 	 */
canAccessSilentAC3()720 	public static boolean canAccessSilentAC3()
721 	{
722 		return canAccessSilentAC3;
723 	}
724 
725 	/**
726 	 * changes the byte order, fixed to 2bytes len ATM!
727 	 */
changeByteOrder(byte[] data, int off, int len)728 	public static void changeByteOrder(byte[] data, int off, int len)
729 	{
730 		for (int i = off, j = len - 1; i < j; i += 2)
731 		{
732 			temp_byte = data[i + 1];
733 			data[i + 1] = data[i];
734 			data[i] = temp_byte;
735 		}
736 
737 		if ((len & 1) != 0)
738 			setMessage("!> byte swap, len has an odd value: " + len + " /off " + off);
739 	}
740 
741 	// should try a while to rename with success, if file_system is blocked by another app.
renameTo(File oldfile, File newfile)742 	public static boolean renameTo(File oldfile, File newfile)
743 	{
744 		//explicit call, otherwise java >= 1.5 ? doesnt release a closed file object immediately
745 		System.gc();
746 
747 		for (int i = 0; i < 10000; i++)
748 			if ( oldfile.renameTo(newfile) )
749 				return true;
750 
751 		setMessage(Resource.getString("common.rename_error1") + " '" + oldfile.toString() + "' " + Resource.getString("common.rename_error2") + " '" + newfile.toString() + "'", true, 0xFFE0E0);
752 
753 		return false;
754 	}
755 
756 	/**
757 	 *
758 	 */
renameTo(String oldfile, String newfile)759 	public static boolean renameTo(String oldfile, String newfile)
760 	{
761 		return renameTo(new File(oldfile), new File(newfile));
762 	}
763 
764 	/**
765 	 *
766 	 */
adaptString(int value, int len)767 	public static String adaptString(int value, int len)
768 	{
769 		return adaptString(String.valueOf(value), len);
770 	}
771 
772 	/**
773 	 *
774 	 */
adaptString(String str, int len)775 	public static String adaptString(String str, int len)
776 	{
777 		StringBuffer strbuf = new StringBuffer(str.trim());
778 
779 		while (strbuf.length() < len)
780 			strbuf.insert(0, "0");
781 
782 		return strbuf.toString();
783 	}
784 
785 	/**
786 	 *
787 	 */
formatTime_1(long time_value)788 	public static String formatTime_1(long time_value)
789 	{
790 		time_format_1.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
791 		return time_format_1.format(new Date(time_value));
792 	}
793 
794 	/**
795 	 *
796 	 */
formatTime_2(long time_value, long frame_rate)797 	public static String formatTime_2(long time_value, long frame_rate)
798 	{
799 		time_format_2.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
800 		String time_str = time_format_2.format(new Date(time_value));
801 
802 		return (time_str.substring(0, time_str.length() - 3) + adaptString((Integer.parseInt(time_str.substring(time_str.length() - 3)) * 90 / (int)frame_rate), 2));
803 	}
804 
805 	/**
806 	 *
807 	 */
formatTime_2a(long time_value)808 	public static String formatTime_2a(long time_value)
809 	{
810 		time_format_2.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
811 		return time_format_2.format(new Date(time_value));
812 	}
813 
814 	/**
815 	 *
816 	 */
formatTime_3(long time_value)817 	public static String formatTime_3(long time_value)
818 	{
819 		//time_format_3.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
820 		return time_format_3.format(new Date(time_value));
821 	}
822 
823 	/**
824 	 *
825 	 */
formatTime_4(long time_value)826 	public static String formatTime_4(long time_value)
827 	{
828 		time_format_4.setTimeZone(TimeZone.getTimeZone("GMT+0:00"));
829 		return time_format_4.format(new Date(time_value));
830 	}
831 
832 	/**
833 	 *
834 	 */
formatTime_5(long time_value)835 	public static String formatTime_5(long time_value)
836 	{
837 		time_format_5.setTimeZone(TimeZone.getDefault());
838 		return time_format_5.format(new Date(time_value));
839 	}
840 
841 	/**
842 	 *
843 	 */
getColorModels()844 	public static Object[] getColorModels()
845 	{
846 		return subpicture_colormodels.toArray();
847 	}
848 
849 	/**
850 	 *
851 	 */
getColorModelsList()852 	public static ArrayList getColorModelsList()
853 	{
854 		return subpicture_colormodels;
855 	}
856 
857 	/**
858 	 *
859 	 */
loadColorModels()860 	private static ArrayList loadColorModels()
861 	{
862 		ArrayList list = new ArrayList();
863 
864 		list.add(Resource.getString("SubtitlePanel.Colormodel.Mode0"));
865 		list.add(Resource.getString("SubtitlePanel.Colormodel.Mode1"));
866 		list.add(Resource.getString("SubtitlePanel.Colormodel.Mode2"));
867 
868 		URL url = Resource.getResourceURL(COLOUR_TABLES_FILENAME);
869 
870 		if (url == null)
871 			return list;
872 
873 		try {
874 			BufferedReader table = new BufferedReader(new InputStreamReader(url.openStream()));
875 			String line;
876 
877 			while( (line = table.readLine()) != null)
878 			{
879 				if ( line.trim().length() == 0 )
880 					continue;
881 
882 				if ( line.startsWith("table") )
883 					list.add( (line.substring( line.indexOf("=") + 1)).trim() );
884 			}
885 
886 			table.close();
887 
888 		} catch (IOException e) {
889 
890 			System.err.println("IOException loadColorModels " + e);
891 		}
892 
893 		if (list.size() <= 3)
894 			canAccessColorTable = false;
895 
896 		return list;
897 	}
898 
899 	/**
900 	 *
901 	 */
getUserColourTable(String model)902 	public static Hashtable getUserColourTable(String model) throws IOException
903 	{
904 		Hashtable user_table = new Hashtable();
905 
906 		URL url = Resource.getResourceURL(COLOUR_TABLES_FILENAME);
907 
908 		if ( url == null )
909 			return user_table;
910 
911 		BufferedReader table = new BufferedReader( new InputStreamReader(url.openStream()));
912 		String line;
913 		boolean table_match = false;
914 
915 		while( (line = table.readLine()) != null)
916 		{
917 			if ( line.trim().length() == 0 )
918 				continue;
919 
920 			if ( line.startsWith("table") )
921 				table_match = line.substring( line.indexOf("=") + 1).trim().equals(model);
922 
923 			else if (table_match)
924 			{
925 				if ( line.startsWith("model") )
926 					user_table.put( "model", line.substring( line.indexOf("=") + 1).trim() );
927 
928 				else
929 					user_table.put( line.substring(0, line.indexOf("=")).trim(), line.substring( line.indexOf("=") + 1).trim() );
930 			}
931 		}
932 
933 		table.close();
934 
935 		if ( !user_table.isEmpty() && !user_table.containsKey("model") )
936 			user_table.put( "model", "16");
937 
938 		return user_table;
939 	}
940 
941 
942 	/**
943 	 * Loads the ac3.bin file.
944 	 */
loadAC3()945 	public static void loadAC3()
946 	{
947 		AudioFormat audio = new AudioFormat(CommonParsing.AC3_AUDIO);
948 		AC3list.clear();
949 
950 		try {
951 			URL url = Resource.getResourceURL(AC3_FILENAME);
952 
953 			if (url != null)
954 			{
955 				BufferedInputStream bis = new BufferedInputStream(url.openStream());
956 				ByteArrayOutputStream bao = new ByteArrayOutputStream();
957 
958 				byte[] buff = new byte[1024];
959 				int bytesRead = -1;
960 
961 				while ((bytesRead = bis.read(buff, 0, buff.length)) != -1)
962 					bao.write(buff, 0, bytesRead);
963 
964 				byte[] check = bao.toByteArray();
965 
966 				setMessage(Resource.getString("ac3.msg.loading.start"));
967 
968 				int a = 0, frame_counter = 0;
969 
970 				while (a < check.length)
971 				{
972 					audio.parseHeader(check, a);
973 					setMessage("(" + frame_counter + ") " + audio.saveAndDisplayHeader());
974 
975 					byte[] ac3data = new byte[audio.getSize()];
976 
977 					System.arraycopy(check, a, ac3data, 0, audio.getSize());
978 
979 					AC3list.add(ac3data);
980 
981 					a += audio.getSize();
982 					frame_counter++;
983 				}
984 
985 				check = null;
986 			}
987 
988 		} catch (IOException e5) {
989 
990 			setExceptionMessage(e5);
991 			AC3list.clear();
992 		}
993 
994 		if (AC3list.size() > 0)
995 			setMessage(Resource.getString("ac3.msg.frames", "" + AC3list.size()));
996 
997 		else
998 			canAccessSilentAC3 = false;
999 	}
1000 
1001 
1002 	/**
1003 	 * Returns the AC3list.
1004 	 *
1005 	 * @return ArrayList
1006 	 */
getAC3list()1007 	public static List getAC3list()
1008 	{
1009 		return AC3list;
1010 	}
1011 
1012 
getFonts()1013 	public static Object[] getFonts()
1014 	{
1015 		Object[] fonts = new Object[0];
1016 
1017 		try {
1018 			fonts = (Object[]) GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
1019 
1020 		} catch (Exception exc) {
1021 			System.out.println(Resource.getString("SubtitlePanel.Font.LoadError") + ": " + exc);
1022 
1023 		} catch (Error err) {
1024 			System.out.println(Resource.getString("SubtitlePanel.Font.LoadError") + ": " + err);
1025 		}
1026 
1027 		return fonts;
1028 	}
1029 
1030 	/**
1031 	 *
1032 	 */
appendLogMessage(String str)1033 	public static void appendLogMessage(String str)
1034 	{
1035 		messagelog += getLineSeparator() + str;
1036 	}
1037 
1038 	/**
1039 	 *
1040 	 */
clearMessageLog()1041 	public static void clearMessageLog()
1042 	{
1043 		messagelog = "";
1044 		ErrorCount = 0;
1045 	}
1046 
1047 	/**
1048 	 *
1049 	 */
getMessageLog()1050 	public static String getMessageLog()
1051 	{
1052 		return messagelog;
1053 	}
1054 
1055 	/**
1056 	 *
1057 	 */
getErrorCount()1058 	public static int getErrorCount()
1059 	{
1060 		return ErrorCount;
1061 	}
1062 
1063 	/**
1064 	 * messages
1065 	 *
1066 	 * @param1 - the msg
1067 	 */
setMessage(Object[] obj)1068 	public static void setMessage(Object[] obj)
1069 	{
1070 		for (int i = 0; obj != null && i < obj.length; i++)
1071 			setMessage(obj[i].toString());
1072 	}
1073 
1074 	/**
1075 	 * messages
1076 	 *
1077 	 * @param1 - the msg
1078 	 */
setMessage(String msg)1079 	public static void setMessage(String msg)
1080 	{
1081 		setMessage(msg, false);
1082 	}
1083 
1084 	/**
1085 	 * messages of interest, also with current systems time_index
1086 	 *
1087 	 * @param1 - the msg
1088 	 * @param2 - force windows visibility
1089 	 */
setMessage(String msg, boolean tofront)1090 	public static void setMessage(String msg, boolean tofront)
1091 	{
1092 		setMessage(msg, tofront, -1);
1093 	}
1094 
1095 	/**
1096 	 * messages of interest, also with current systems time_index
1097 	 *
1098 	 * @param1 - the msg
1099 	 * @param2 - force windows visibility
1100 	 */
setMessage(String msg, boolean tofront, int background)1101 	public static void setMessage(String msg, boolean tofront, int background)
1102 	{
1103 		if (msg == null)
1104 		{
1105 			if (!isRunningCLI())
1106 			{
1107 				if (getGuiInterface() != null)
1108 					getGuiInterface().setMessage(msg, tofront, background);
1109 
1110 				else
1111 					System.out.println(msg);
1112 			}
1113 
1114 			return;
1115 		}
1116 
1117 		if (msg.startsWith("!>"))
1118 		{
1119 			ErrorCount++;
1120 
1121 			if (MaxLog && ErrorCount > 500)
1122 				return;
1123 		}
1124 
1125 		if (MaxLog && ErrorCount == 500)
1126 			msg += getLineSeparator() + getLineSeparator() + Resource.getString("all.msg.error.max") + getLineSeparator();
1127 
1128 		if (TimeLog)
1129 			msg = "[" + formatTime_1(System.currentTimeMillis()) + "] " + msg;
1130 
1131 		if (getGlobalDebug())
1132 			System.out.println(msg);
1133 
1134 		if (isRunningCLI() || getGuiInterface() == null)
1135 			System.out.println(msg);
1136 
1137 		else
1138 			getGuiInterface().setMessage(msg, tofront, background);
1139 
1140 		appendLogMessage(msg);
1141 	}
1142 
1143 	/**
1144 	 * messages
1145 	 *
1146 	 * @param1 - the msg
1147 	 */
setExceptionMessage(Exception exc)1148 	public static void setExceptionMessage(Exception exc)
1149 	{
1150 		StringWriter sw = new StringWriter();
1151 		exc.printStackTrace(new PrintWriter(sw));
1152 
1153 		setErrorMessage(sw.toString());
1154 	}
1155 
1156 	/**
1157 	 * messages
1158 	 *
1159 	 * @param1 - the msg
1160 	 */
setErrorMessage(Error err)1161 	public static void setErrorMessage(Error err)
1162 	{
1163 		StringWriter sw = new StringWriter();
1164 		err.printStackTrace(new PrintWriter(sw));
1165 
1166 		setErrorMessage(sw.toString());
1167 	}
1168 
1169 	/**
1170 	 * messages
1171 	 *
1172 	 * @param1 - the msg
1173 	 */
setErrorMessage(String str)1174 	public static void setErrorMessage(String str)
1175 	{
1176 		/**
1177 		 * show error messge
1178 		 */
1179 		setMessage("");
1180 		setMessage("!> an error has occured..  (please inform the authors at 'forum.dvbtechnics.info')");
1181 		setMessage(str, true, 0xFFE0E0);
1182 	}
1183 
1184 	/**
1185 	 * messages
1186 	 *
1187 	 * @param1 - the msg
1188 	 */
setOSDMessage(String str)1189 	public static void setOSDMessage(String str)
1190 	{
1191 		setOSDMessage(str, false);
1192 	}
1193 
1194 	/**
1195 	 * messages
1196 	 *
1197 	 * @param1 - the msg
1198 	 */
setOSDErrorMessage(String str)1199 	public static void setOSDErrorMessage(String str)
1200 	{
1201 		setOSDMessage(str, true);
1202 	}
1203 
1204 	/**
1205 	 * messages
1206 	 *
1207 	 * @param1 - the msg
1208 	 * @param2 - is error
1209 	 */
setOSDMessage(String str, boolean b)1210 	public static void setOSDMessage(String str, boolean b)
1211 	{
1212 		getGuiInterface().setOSDMessage(str, b);
1213 	}
1214 
1215 	/**
1216 	 * post commands
1217 	 */
performCommand(String str)1218 	public static void performCommand(String str)
1219 	{
1220 		if (str == null || str.trim().length() == 0)
1221 			return;
1222 
1223 		try {
1224 			Runtime.getRuntime().exec(str);
1225 
1226 		} catch (Exception ex) {
1227 			setExceptionMessage(ex);
1228 		}
1229 	}
1230 
1231 	/**
1232 	 * post commands
1233 	 */
performPostCommand(Object[] lastlist)1234 	public static void performPostCommand(Object[] lastlist)
1235 	{
1236 		if (!getSettings().getBooleanProperty(Keys.KEY_enablePostProcessing))
1237 			return;
1238 
1239 		String cmdl = "";
1240 
1241 		switch (getSettings().getIntProperty(Keys.KEY_ConversionMode))
1242 		{
1243 		case CommonParsing.ACTION_DEMUX:
1244 			cmdl = getSettings().getProperty(Keys.KEY_PostCommands_Cmd4);
1245 			break;
1246 
1247 		case CommonParsing.ACTION_TO_VDR:
1248 			cmdl = getSettings().getProperty(Keys.KEY_PostCommands_Cmd5);
1249 			break;
1250 
1251 		case CommonParsing.ACTION_TO_M2P:
1252 			cmdl = getSettings().getProperty(Keys.KEY_PostCommands_Cmd6);
1253 			break;
1254 
1255 		case CommonParsing.ACTION_TO_PVA:
1256 			cmdl = getSettings().getProperty(Keys.KEY_PostCommands_Cmd7);
1257 			break;
1258 
1259 		case CommonParsing.ACTION_TO_TS:
1260 			cmdl = getSettings().getProperty(Keys.KEY_PostCommands_Cmd8);
1261 			break;
1262 
1263 		default:
1264 			return;
1265 		}
1266 
1267 		cmdl = cmdl.trim();
1268 
1269 		if (cmdl.length() > 0 && lastlist.length > 0)
1270 		{
1271 			ArrayList argList = new ArrayList();
1272 
1273 			String append_str = "";
1274 			boolean isQuoted = false;
1275 
1276 			int appending = cmdl.lastIndexOf(" \"?");
1277 
1278 			if (appending < 0)
1279 				appending = cmdl.lastIndexOf(" ?");
1280 			else
1281 				isQuoted = true;
1282 
1283 			if (appending < 0)
1284 				argList.add(cmdl.trim());
1285 
1286 			else
1287 			{
1288 				append_str = cmdl.substring(appending).replace('"', ' ').trim();
1289 
1290 				cmdl = cmdl.substring(0, appending).trim();
1291 				argList.add(cmdl);
1292 
1293 				appending = Integer.parseInt(append_str.substring(1));
1294 
1295 				if (appending == 0 || appending > lastlist.length)
1296 					appending = lastlist.length;
1297 
1298 				for (int l = 0; l < lastlist.length && l < appending; l++)
1299 				{
1300 					String str = lastlist[l].toString();
1301 					str = str.substring(str.indexOf("'") + 1, str.length() - 1);
1302 
1303 					if (isQuoted)
1304 						argList.add("" + (char)34 + str + (char)34);
1305 					else
1306 						argList.add(str);
1307 				}
1308 			}
1309 
1310 			String commandline = "";
1311 			String[] arguments = new String[argList.size()];
1312 
1313 			for (int l = 0; l < arguments.length; l++)
1314 			{
1315 				arguments[l] = argList.get(l).toString();
1316 				commandline += l == 0 ? "" : " ";
1317 				commandline += arguments[l];
1318 			}
1319 
1320 			setMessage(Resource.getString("working.post.command") + " {" + commandline + "}");
1321 
1322 
1323 			try {
1324 				Process subprocess = Runtime.getRuntime().exec(commandline); // anyone has told that works better
1325 			//	Process subprocess = Runtime.getRuntime().exec(arguments);
1326 
1327 				if (getSettings().getBooleanProperty(Keys.KEY_PostProcessCompletion))
1328 				{
1329 					setMessage("-> waiting for completion of subprocess..");
1330 					setMessage("-> returncode of subprocess: " + subprocess.waitFor());
1331 				}
1332 
1333 			} catch (Exception re)	{
1334 
1335 				setExceptionMessage(re);
1336 			}
1337 
1338 			argList = null;
1339 		}
1340 	}
1341 
1342 	/**
1343 	 * should support loading of supported URLs/files via CLI
1344 	 */
getInputFile(String value)1345 	public static XInputFile getInputFile(String value)
1346 	{
1347 		XInputFile inputValue = null;
1348 		URL url = null;
1349 
1350 		if (value == null)
1351 			return null;
1352 
1353 		try
1354 		{
1355 			url = new URL(value);
1356 
1357 			String protocol = url.getProtocol();
1358 
1359 			if (protocol.equals("ftp"))
1360 			{
1361 				XInputDirectory xid = new XInputDirectory(url);
1362 				XInputFile[] xif = xid.getFiles();
1363 
1364 				for (int i = 0; i < xif.length; i++)
1365 				{
1366 					if ( new URL(xif[i].toString()).getFile().equals(url.getFile()) )
1367 					{
1368 						inputValue = xif[i];
1369 						break;
1370 					}
1371 				}
1372 			}
1373 
1374 			else if (protocol.equals("file"))
1375 				inputValue = new XInputFile(new File(url.getHost() + url.getFile()));
1376 
1377 			else
1378 				System.out.println("!> Protocol not yet supported: " + protocol);
1379 
1380 			return inputValue;
1381 		}
1382 		catch (Exception u1)
1383 		{}
1384 
1385 		try {
1386 			File f = new File(value);
1387 
1388 			if (f.exists())
1389 			{
1390 				inputValue = new XInputFile(f);
1391 
1392 				return inputValue;
1393 			}
1394 
1395 		} catch (Exception e) {
1396 			System.out.println("local Filesystem access: '" + value + "' > " + e);
1397 		}
1398 
1399 		try {
1400 			inputValue = new XInputFile(value);
1401 			return inputValue;
1402 
1403 		} catch (Exception e) {
1404 			System.out.println("ext. Filesystem access: '" + value + "' > " + e);
1405 		}
1406 
1407 		return null;
1408 	}
1409 
1410 	/**
1411 	 * show java EV
1412 	 */
getJavaEV(String inifile)1413 	public static Object[] getJavaEV(String inifile)
1414 	{
1415 		List list = new ArrayList();
1416 
1417 		list.add("Java Environment");
1418 		list.add(getDateAndTime());
1419 		list.add(Resource.getString("javaev.java.version") + "\t" + System.getProperty("java.version"));
1420 		list.add(Resource.getString("javaev.java.vendor") + "\t" + System.getProperty("java.vendor"));
1421 		list.add(Resource.getString("javaev.java.home") + "\t" + System.getProperty("java.home"));
1422 		list.add(Resource.getString("javaev.java.vm.version") + "\t" + System.getProperty("java.vm.version"));
1423 		list.add(Resource.getString("javaev.java.vm.vendor") + "\t" + System.getProperty("java.vm.vendor"));
1424 		list.add(Resource.getString("javaev.java.vm.name") + "\t" + System.getProperty("java.vm.name"));
1425 		list.add(Resource.getString("javaev.java.class.vers") + "\t" + System.getProperty("java.class.version"));
1426 		list.add(Resource.getString("javaev.java.class.path") + "\t" + System.getProperty("java.class.path"));
1427 		list.add(Resource.getString("javaev.java.os.name") + "\t" + System.getProperty("os.name"));
1428 		list.add(Resource.getString("javaev.java.os.arch") + "\t" + System.getProperty("os.arch"));
1429 		list.add(Resource.getString("javaev.java.os.version") + "\t" + System.getProperty("os.version"));
1430 		list.add(Resource.getString("javaev.java.ini.file") + "\t" + inifile);
1431 
1432 		String str = (new RawInterface("")).GetLoadStatus();
1433 
1434 		if (str == null)
1435 		{
1436 			str = Resource.getString("rawread.msg1");
1437 			canAccessRawread = false;
1438 		}
1439 
1440 		list.add(Resource.getString("javaev.java.disk.access") + "\t" + str);
1441 		list.add(Resource.getString("javaev.java.user.lang") + "\t" + Resource.getChosenLanguage());
1442 		list.add(Resource.getString("javaev.java.user.name") + "\t" + System.getProperty("user.name"));
1443 		list.add(Resource.getString("javaev.java.user.home") + "\t" + System.getProperty("user.home"));
1444 
1445 		return list.toArray();
1446 	}
1447 
1448 
1449 	/**
1450 	 *
1451 	 */
getDataTroughput()1452 	public static String getDataTroughput()
1453 	{
1454 		long val = (Data_Troughput[1] - Data_Troughput[0]) / 1024L;
1455 
1456 		Data_Troughput[1] = Data_Troughput[0] = 0;
1457 
1458 		return String.valueOf(val < 0 ? 0 : val);
1459 	}
1460 
1461 	/**
1462 	 *
1463 	 */
getFps()1464 	public static String getFps()
1465 	{
1466 		int val = FpsValue[1] - FpsValue[0];
1467 
1468 		FpsValue[1] = FpsValue[0] = 0;
1469 
1470 		return String.valueOf(val < 0 ? 0 : val);
1471 	}
1472 
1473 	/**
1474 	 *
1475 	 */
setFps(int val)1476 	public static void setFps(int val)
1477 	{
1478 		if (FpsValue[0] == 0)
1479 			FpsValue[1] = FpsValue[0] = val;
1480 
1481 		else
1482 			FpsValue[1] = val;
1483 	}
1484 
1485 	/**
1486 	 *
1487 	 */
getExportedSize()1488 	public static String getExportedSize()
1489 	{
1490 		JobCollection collection = getCollection(getProcessedCollection());
1491 
1492 		long val = collection == null || collection.getJobProcessing() == null ? 0 : collection.getJobProcessing().getMediaFilesExportLength() / 1048576L;
1493 
1494 		return String.valueOf(val) + " MB - " + SplitPart;
1495 	}
1496 
1497 	/**
1498 	 *
1499 	 */
showSplitPart(int value)1500 	public static void showSplitPart(int value)
1501 	{
1502 		SplitPart = value;
1503 	}
1504 
1505 	/**
1506 	 * progress
1507 	 */
getProcessedPercent()1508 	public static int getProcessedPercent()
1509 	{
1510 		return ProcessedPercent;
1511 	}
1512 
1513 	/**
1514 	 * progress
1515 	 *
1516 	 * @param1 - the msg
1517 	 */
updateProgressBar(long position, long size)1518 	public static void updateProgressBar(long position, long size)
1519 	{
1520 		if (Data_Troughput[0] == 0)
1521 			Data_Troughput[1] = Data_Troughput[0] = position;
1522 
1523 		else
1524 			Data_Troughput[1] = position;
1525 
1526 		if (size <= 0)
1527 			size = 1;
1528 
1529 		int percent = (int)(position * 100 / size) + 1;
1530 
1531 		if (percent == ProcessedPercent)
1532 			return;
1533 
1534 		ProcessedPercent = percent;
1535 
1536 		getGuiInterface().updateProgressBar(ProcessedPercent);
1537 	}
1538 
1539 	/**
1540 	 * progress
1541 	 *
1542 	 * @param1 - the msg
1543 	 */
updateProgressBar(String str)1544 	public static void updateProgressBar(String str)
1545 	{
1546 		setStatusString(str);
1547 		getGuiInterface().updateProgressBar(str);
1548 	}
1549 
1550 	/**
1551 	 * progress
1552 	 *
1553 	 * @param1 - the msg
1554 	 * @param2 - %
1555 	 */
updateProgressBar(String str, long position, long size)1556 	public static void updateProgressBar(String str, long position, long size)
1557 	{
1558 		if (str != null)
1559 			updateProgressBar(str);
1560 
1561 		updateProgressBar(position, size);
1562 	}
1563 
1564 	/**
1565 	 *
1566 	 */
getStatusString()1567 	public static String getStatusString()
1568 	{
1569 		return StatusString;
1570 	}
1571 
1572 	/**
1573 	 *
1574 	 */
setStatusString(String str)1575 	public static void setStatusString(String str)
1576 	{
1577 		StatusString = str;
1578 	}
1579 
1580 	/**
1581 	 * Checks the latest version of Project-X
1582 	 */
checkVersion()1583 	public static void checkVersion()
1584 	{
1585 		try {
1586 			URL url = new URL("http://project-x.sourceforge.net/update/update.txt");
1587 			URLConnection urlConn = url.openConnection();
1588 			BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
1589 
1590 			String line = br.readLine();
1591 			String version = line;
1592 			String date = null;
1593 
1594 			if (line != null)
1595 			{
1596 				StringTokenizer st = new StringTokenizer(line, ";");
1597 
1598 				if (st.hasMoreTokens())
1599 					version = st.nextToken();
1600 
1601 				if (st.hasMoreTokens())
1602 					date = st.nextToken();
1603 			}
1604 
1605 			if (date != null)
1606 				version += "\n" + date;
1607 
1608 			getGuiInterface().showMessageDialog(Resource.getString("help.version.info") + "\n"+version, Resource.getString("help.version.info.title"));
1609 
1610 		} catch(Exception e) {
1611 
1612 			setExceptionMessage(e);
1613 		}
1614 	}
1615 
1616 	/**
1617 	 *
1618 	 */
getMainFrameBounds()1619 	public static void getMainFrameBounds()
1620 	{
1621 		Rectangle rect = (Rectangle) getGuiInterface().getMainFrameBounds();
1622 
1623 		if (rect != null)
1624 		{
1625 			getSettings().setIntProperty(Keys.KEY_WindowPositionMain_X[0], (int) rect.getX());
1626 			getSettings().setIntProperty(Keys.KEY_WindowPositionMain_Y[0], (int) rect.getY());
1627 			getSettings().setIntProperty(Keys.KEY_WindowPositionMain_Width[0], (int) rect.getWidth());
1628 			getSettings().setIntProperty(Keys.KEY_WindowPositionMain_Height[0], (int) rect.getHeight());
1629 		}
1630 	}
1631 
1632 	/**
1633 	 *
1634 	 */
showMainFrame(boolean b)1635 	public static void showMainFrame(boolean b)
1636 	{
1637 		getGuiInterface().showMainFrame(b);
1638 	}
1639 
1640 	/**
1641 	 *
1642 	 */
setFrameTitle(String str)1643 	public static void setFrameTitle(String str)
1644 	{
1645 		getGuiInterface().setMainFrameTitle(str);
1646 	}
1647 
1648 	/**
1649 	 *
1650 	 */
addCollectionAtEnd()1651 	public static void addCollectionAtEnd()
1652 	{
1653 		if (getGuiInterface() != null)
1654 			getGuiInterface().addCollectionAtEnd();
1655 	}
1656 
1657 	/**
1658 	 * refresh inputfileslist
1659 	 */
reloadInputDirectories()1660 	public static Object[] reloadInputDirectories()
1661 	{
1662 		ArrayList arraylist = new ArrayList();
1663 		ArrayList input_directories = Common.getSettings().getInputDirectories();
1664 
1665 		for (int a = 0; a < input_directories.size(); a++)
1666 		{
1667 			// Get input files
1668 			Object item = input_directories.get(a);
1669 
1670 			XInputDirectory xInputDirectory = (XInputDirectory) item;
1671 			XInputFile[] addlist = xInputDirectory.getFiles();
1672 
1673 			// Sort them
1674 			if (addlist.length > 0)
1675 			{
1676 				class MyComparator implements Comparator {
1677 					public int compare(Object o1, Object o2)
1678 					{
1679 						return o1.toString().compareTo(o2.toString());
1680 					}
1681 				}
1682 
1683 				Arrays.sort(addlist, new MyComparator());
1684 			}
1685 
1686 			// Add them to the list
1687 			for (int b = 0; b < addlist.length; b++)
1688 				arraylist.add(addlist[b]);
1689 		}
1690 
1691 		try {
1692 			// Get input files from topfield raw disk access
1693 			XInputDirectory xInputDirectory = new XInputDirectory(DirType.RAW_DIR);
1694 			XInputFile[] addlist = xInputDirectory.getFiles();
1695 
1696 			// Sort them
1697 			if (addlist.length > 0)
1698 			{
1699 				class MyComparator implements Comparator
1700 				{
1701 					public int compare(Object o1, Object o2)
1702 					{
1703 						return o1.toString().compareTo(o2.toString());
1704 					}
1705 				}
1706 
1707 				Arrays.sort(addlist, new MyComparator());
1708 			}
1709 
1710 			// Add them to the list
1711 			for (int b = 0; b < addlist.length; b++)
1712 				arraylist.add(addlist[b]);
1713 
1714 		} catch (Throwable t) {
1715 			// Assume no dll available or no hd or no file, so do nothing!
1716 		}
1717 
1718 		return (arraylist.isEmpty() ? new Object[0] : arraylist.toArray());
1719 	}
1720 
1721 	/**
1722 	 *
1723 	 */
setLastPreviewBitrate(int value)1724 	public static void setLastPreviewBitrate(int value)
1725 	{
1726 		LastPreviewBitrate = value / 8;
1727 	}
1728 
1729 	/**
1730 	 *
1731 	 */
getPreviewBufferValue()1732 	public static int getPreviewBufferValue()
1733 	{
1734 		String str = getSettings().getProperty(Keys.KEY_PreviewBuffer);
1735 		int buffervalue = LastPreviewBitrate;
1736 
1737 		try {
1738 			if (!str.equals("auto"))
1739 				buffervalue = Integer.parseInt(str);
1740 
1741 		} catch (Exception e) {}
1742 
1743 		if (buffervalue < 128000 || buffervalue > 5120000)
1744 			LastPreviewBitrate = buffervalue = 1875000;
1745 
1746 		return buffervalue;
1747 	}
1748 
1749 	/**
1750 	 *
1751 	 */
getNewFileID()1752 	public static String getNewFileID()
1753 	{
1754 		FileID++;
1755 
1756 		return String.valueOf(FileID);
1757 	}
1758 
1759 }