noSplash = !noSplash ? webserverMode && username != null : noSplash;
installationDir = dir != null ? dir : installationDir;
if (installationDir == null || installationDir.trim().length() == 0) {
NativeMessageBox dialog = new NativeMessageBox("Warning",
"The installation directory could not be determined. " +
"Please set the DATACROW_HOME environment variable or supply the -dir:<installation directory> parameter. " +
"The DATACROW_HOME variable value should point to the Data Crow intallation directory.");
DcSwingUtilities.openDialogNativeModal(dialog);
return;
}
DataCrow.installationDir = DataCrow.installationDir.replaceAll("\\\\", "/");
DataCrow.installationDir += !DataCrow.installationDir.endsWith("\\") && !DataCrow.installationDir.endsWith("/") ? "/" : "";
long totalstart = 0;
try {
if (!new File("datacrow.chk").exists() && (platform.isVista() || platform.isWindows7())) {
NativeMessageBox dlg = new NativeMessageBox(
"Windows 7 / Windows Vista",
"For Windows Vista and Windows 7 users you have to select to run Data Crow 'as administrator'. " +
"Right click 'datacrow.exe' and select 'run as administrator'. You can also choose to modify " +
"the shortcut. Right click on the shortcut and select the 'compatibility' tab. Tick the option " +
"'run as administrator'.");
DcSwingUtilities.openDialogNativeModal(dlg);
new File("datacrow.chk").createNewFile();
}
checkCurrentDir();
createDirectories();
initLog4j();
logger = Logger.getLogger(DataCrow.class.getName());
totalstart = logger.isDebugEnabled() ? new Date().getTime() : 0;
installLafs();
logger.info(new Date() + " Starting Data Crow. ");
logger.info("Using installation directory: " + installationDir);
logger.info("Using data directory: " + dataDir);
logger.info("Using images directory: " + imageDir);
// load resources
new DcResources();
new DcSettings();
checkPlatform();
if (DcSettings.getString(DcRepository.Settings.stLanguage) == null ||
DcSettings.getString(DcRepository.Settings.stLanguage).trim().equals("")) {
SelectLanguageDialog dlg = new SelectLanguageDialog();
DcSwingUtilities.openDialogNativeModal(dlg);
}
showSplashScreen();
// check if the web module has been installed
isWebModuleInstalled = new File(DataCrow.webDir, "WEB-INF").exists();
// initialize plugins
Plugins.getInstance();
// initialize services
Servers.getInstance();
// Initialize the Component factory
new ComponentFactory();
Enumeration en = Logger.getRootLogger().getAllAppenders();
while (en.hasMoreElements()) {
Appender appender = (Appender) en.nextElement();
if (appender instanceof TextPaneAppender)
((TextPaneAppender) appender).addListener(LogPanel.getInstance());
}
logger.info(DcResources.getText("msgApplicationStarts"));
// Initialize all modules
showSplashMsg(DcResources.getText("msgLoadingModules"));
long start = logger.isDebugEnabled() ? new Date().getTime() : 0;
new ModuleUpgrade().upgrade();
if (logger.isDebugEnabled()) {
long end = new Date().getTime();
logger.debug("Upgrading the modules took " + (end - start) + "ms");
}
start = logger.isDebugEnabled() ? new Date().getTime() : 0;
DcModules.load();
if (logger.isDebugEnabled()) {
long end = new Date().getTime();
logger.debug("Loading the modules took " + (end - start) + "ms");
}
logger.info(DcResources.getText("msgModulesLoaded"));
ValueEnhancers.initialize();
// delete lock file
Directory directory = new Directory(dataDir, false, new String[] {"lck"});
for (String file : directory.read())
new File(file).delete();
// set the database name
DcSettings.set(DcRepository.Settings.stConnectionString, "dc");
if (db != null && db.length() > 0)
DcSettings.set(DcRepository.Settings.stConnectionString, db);
initDbProperties();
start = logger.isDebugEnabled() ? new Date().getTime() : 0;
SecurityCentre.getInstance().initialize();
if (logger.isDebugEnabled()) {
long end = new Date().getTime();
logger.debug("Initilization of the security center took " + (end - start) + "ms");
}
// log in
login(username, password);
// Establish a connection to the database / server
showSplashMsg(DcResources.getText("msgInitializingDB"));
DatabaseManager.initialize();
// Start the UI
if (splashScreen == null)
showSplashScreen();
showSplashMsg(DcResources.getText("msgLoadingItems"));
DcModules.loadData();
checkTabs();
loadDefaultData();
if (!webserverMode)
showSplashMsg(DcResources.getText("msgLoadingUI"));
// load the filters & patterns
DataFilters.load();
FilePatterns.load();
ComponentFactory.setLookAndFeel();
if (!webserverMode) {
mainFrame = new MainFrame();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
long start = logger.isDebugEnabled() ? new Date().getTime() : 0;
DataCrow.mainFrame.initialize();
DataCrow.mainFrame.setVisible(true);
mainFrame.setViews();
if (logger.isDebugEnabled()) {
long end = new Date().getTime();
logger.debug("Initilization of the UI took " + (end - start) + "ms");
}
}
});
} else {
if (!SecurityCentre.getInstance().getUser().isAuthorized("WebServer")) {
DcSwingUtilities.displayWarningMessage("msgWebServerStartUnauthorized");
new ShutdownThread().run();
System.exit(0);
} else {
Runtime.getRuntime().addShutdownHook(new ShutdownThread());
showSplashMsg(DcResources.getText("msgStartingWebServer"));
DcWebServer.getInstance().start();
if (DcWebServer.getInstance().isRunning())
showSplashMsg(DcResources.getText("msgWebServerStarted"));
System.out.println(DcResources.getText("msgCloseWebServerConsole"));
}
}
SystemMonitor monitor = new SystemMonitor();
monitor.start();
Thread splashCloser = new Thread(new SplashScreenCloser());
splashCloser.start();
if (DcSettings.getBoolean(DcRepository.Settings.stCheckForNewVersion))
new VersionChecker().start();
if (!webserverMode) {
DataFilter df = new DataFilter(DcModules._LOAN);
df.addEntry(new DataFilterEntry(DataFilterEntry._AND, DcModules._LOAN, Loan._B_ENDDATE, Operator.IS_EMPTY, null));
df.addEntry(new DataFilterEntry(DataFilterEntry._AND, DcModules._LOAN, Loan._E_DUEDATE, Operator.IS_FILLED, null));
for (DcObject loan : DataManager.get(df)) {
Long overdue = ((Loan) loan).getDaysTillOverdue();
if (overdue != null && overdue.longValue() < 0) {
DcSwingUtilities.displayWarningMessage("msgThereAreOverdueItems");
new LoanInformationForm().setVisible(true);
break;
}
}
}
DcSettings.set(DcRepository.Settings.stGracefulShutdown, Boolean.FALSE);
DcSettings.save();
if (DcSettings.getBoolean(DcRepository.Settings.stDriveScannerRunOnStartup)) {
DriveManagerDialog.getInstance();
DriveManager.getInstance().startScanners();
}
if (DcSettings.getBoolean(DcRepository.Settings.stDrivePollerRunOnStartup)) {
DriveManagerDialog.getInstance();
DriveManager.getInstance().startDrivePoller();
}
initialized = true;
} catch (Exception e) {
if (logger != null) logger.fatal("Severe error occurred while starting Data Crow. The application cannot continue.", e);
e.printStackTrace();
new NativeMessageBox("Error", e.toString());
System.exit(0);
}
int xp = DcSettings.getInt(DcRepository.Settings.stXpMode);
if (!webserverMode && xp == -1) {
SelectExpienceLevelDialog dlg = new SelectExpienceLevelDialog();
dlg.setVisible(true);
}
if (!webserverMode && DcSettings.getBoolean(DcRepository.Settings.stShowTipsOnStartup)) {
TipOfTheDayDialog dlg = new TipOfTheDayDialog();
dlg.setVisible(true);
}
if (!webserverMode && DcSettings.getBoolean(DcRepository.Settings.stShowToolSelectorOnStartup)) {
ToolSelectWizard wizard = new ToolSelectWizard();
wizard.setVisible(true);
}
if (logger.isDebugEnabled()) {
long end = new Date().getTime();
logger.debug("Total startup time was " + (end - totalstart) + "ms");
}
int usage = DcSettings.getInt(DcRepository.Settings.stUsage) + 1;
DcSettings.set(DcRepository.Settings.stUsage, Long.valueOf(usage));
boolean itsTime = usage == 15 || usage == 150 || usage == 1000 || usage == 1500 || usage == 500 || usage == 50;
if (itsTime && DcSettings.getBoolean(DcRepository.Settings.stAskForDonation))
new DonateDialog().setVisible(true);
} catch (Throwable e) {
System.out.println("Data Crow could not be started: " + e);
e.printStackTrace();
new NativeMessageBox("Error", "Data Crow could not be started: " + e);
try {
DcSettings.set(DcRepository.Settings.stGracefulShutdown, Boolean.FALSE);
DcSettings.save();
} catch (Exception ignore) {}