From 43bec1cad4d8ed554484e8c6795cf07601c12074 Mon Sep 17 00:00:00 2001 From: Marko Živković Date: Wed, 25 Feb 2015 22:30:45 +0000 Subject: Major refactoring of everything related to configuration files, especially the way of storing files. git-svn-id: https://svn.code.sf.net/p/xlogo4schools/svn/trunk@24 3b0d7934-f7ef-4143-9606-b51f2e2281fd --- .../src/xlogo/kernel/userspace/files/LogoFile.java | 30 ++++++++++------------ .../xlogo/kernel/userspace/files/RecordFile.java | 10 ++++---- 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'logo/src/xlogo/kernel/userspace/files') diff --git a/logo/src/xlogo/kernel/userspace/files/LogoFile.java b/logo/src/xlogo/kernel/userspace/files/LogoFile.java index 693e3f3..4575f73 100644 --- a/logo/src/xlogo/kernel/userspace/files/LogoFile.java +++ b/logo/src/xlogo/kernel/userspace/files/LogoFile.java @@ -62,7 +62,7 @@ import xlogo.utils.Utils; * This class holds the text file a user entered in the editor. * It analyzes the text and maintains a symbol table for all defined procedures that live within it. *

- * The file does never store itself implicitly, except for when it is created using {@link #createNewFile(String)} or renamed using {@link #setFileName(String)} + * The file does never store itself implicitly, except for when it is created using {@link #createNewFile(String)} or renamed using {@link #setPlainName(String)} * In every other case, {@link #store()}} or {@link #storeCopyToFile(File)}} must be invoked explicitly. *

* The file's text can be set using {@link #setTextFromReader(BufferedReader)}} (preferred) or {@link #setText(String)}}. @@ -116,9 +116,7 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, { super(); this.userConfig = WSManager.getUserConfig(); - if (!userConfig.isVirtual()) - setLocation(userConfig.getSourceDirectory()); - setFileName(fileName); + setPlainName(fileName); executables = new HashMap(); allProcedures = new ArrayList(); } @@ -164,8 +162,6 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, String text = Utils.readLogoFile(path.toString()); LogoFile file = new LogoFile(fileName); file.setText(text); - if (userConfig.isVirtual()) - file.makeVirtual(); return file; } @@ -183,8 +179,6 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, String text = Utils.readLogoFile(path.toString()); LogoFile file = new LogoFile(newFileName); file.setText(text); - if (WSManager.getUserConfig().isVirtual()) - file.makeVirtual(); file.store(); return file; } @@ -200,7 +194,7 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, * @param newFileName - without extension */ @Override - public void setFileName(String newFileName) + public void setPlainName(String newFileName) { logger.trace("Renaming file " + getPlainName() + " to " + newFileName); @@ -221,7 +215,7 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, } String oldPlainName = getPlainName(); - super.setFileName(newFileName); + super.setPlainName(newFileName); String newPlainName = getPlainName(); if (oldPlainName != null) @@ -271,11 +265,9 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, * and another copy in the backup folder, if this is required by {@link WorkspaceConfig#getNumberOfBackups()}. */ @Override - public void store() throws IOException + public void store() { super.store(); - if (isVirtual()) - return; doBackup(); } @@ -299,8 +291,10 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, * defined by {@link WorkspaceConfig#getNumberOfBackups()}} * @throws IOException */ - private void doBackup() throws IOException + private void doBackup() { + if (isVirtual()) + return; logger.trace("Creating backup file of current version of " + getPlainName()); WorkspaceConfig wc = WSManager.getInstance().getWorkspaceConfigInstance(); @@ -311,8 +305,12 @@ public class LogoFile extends StorableDocument implements ExecutablesContainer, if (!backupFolder.exists()) backupFolder.mkdirs(); - if (nob != NumberOfBackups.NO_BACKUPS) - storeCopyToFile(backupFile); + if (nob != NumberOfBackups.NO_BACKUPS) { + try { + storeCopyToFile(backupFile); + } + catch (Exception ignore) { } + } if (nob == NumberOfBackups.INFINITE) return; diff --git a/logo/src/xlogo/kernel/userspace/files/RecordFile.java b/logo/src/xlogo/kernel/userspace/files/RecordFile.java index ed89646..84c6d51 100644 --- a/logo/src/xlogo/kernel/userspace/files/RecordFile.java +++ b/logo/src/xlogo/kernel/userspace/files/RecordFile.java @@ -126,7 +126,7 @@ public class RecordFile extends LogoFile implements MessageBroadcaster totalMillis += now.getTime() - last.getTime(); last = now; - String time = UserConfig.getMinSec(totalMillis); + String time = Utils.getMinSec(totalMillis); String fileName = getPlainName(); for(MessageListener listener : timerEventListeners) @@ -203,9 +203,9 @@ public class RecordFile extends LogoFile implements MessageBroadcaster private String getTimeStampHeader(long totalTime, long lastEditStarted, long lastEditEnded) { - String tot = UserConfig.getMinSec(totalTime); - String lastStart = UserConfig.getTimeString(lastEditStarted); - String now = UserConfig.getTimeString(lastEditEnded); + String tot = Utils.getMinSec(totalTime); + String lastStart = Utils.getTimeString(lastEditStarted); + String now = Utils.getTimeString(lastEditEnded); return "# Total Time : " + tot + "\n# Edited from : " + lastStart + "\n# Until : " + now + "\n\n"; } @@ -222,7 +222,7 @@ public class RecordFile extends LogoFile implements MessageBroadcaster if(listener == null) throw new IllegalArgumentException("Listener must not be null."); timerEventListeners.add(listener); - listener.messageEvent(getPlainName(), UserConfig.getMinSec(totalMillis)); + listener.messageEvent(getPlainName(), Utils.getMinSec(totalMillis)); } @Override -- cgit v1.2.3