Initial commit

This commit is contained in:
Gabriel Tofvesson 2017-06-01 01:25:38 +02:00
commit 2e50bd5fdf
29 changed files with 509 additions and 0 deletions

21
.idea/artifacts/JavaFXApp.xml generated Normal file
View File

@ -0,0 +1,21 @@
<component name="ArtifactManager">
<artifact type="javafx" name="JavaFXApp">
<output-path>$PROJECT_DIR$/out/artifacts/JavaFXApp</output-path>
<properties id="javafx-properties">
<options>
<option name="appClass" value="net.tofvesson.symlinker.Main" />
<option name="description" value="" />
<option name="htmlPlaceholderId" value="" />
<option name="title" value="Symmie" />
<option name="vendor" value="Tofvesson Productions" />
<option name="version" value="1.0" />
</options>
</properties>
<root id="root">
<element id="archive" name="JavaFXApp.jar">
<element id="module-output" name="Symmie" />
<element id="dir-copy" path="$PROJECT_DIR$/src" />
</element>
</root>
</artifact>
</component>

23
.idea/compiler.xml generated Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

2
.idea/description.html generated Normal file
View File

@ -0,0 +1,2 @@
<html>Simple <b>JavaFX 2.0</b> application that includes simple .fxml file with attached controller and Main class to quick start. Artifact to build JavaFX application is provided.
</html>

5
.idea/encodings.xml generated Normal file
View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>

7
.idea/gradle.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="gradleHome" value="C:/Program Files (x86)/Gradle/gradle-1.0-rc-3" />
</component>
</project>

6
.idea/hotswap_agent.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="HotSwapAgentPluginSettingsProvider">
<option name="agentPath" value="C:\Users\Gabriel\.IdeaIC2017.1\config\plugins\hotswap-agent-intellij-plugin\lib\agent\hotswap-agent-1.0.jar" />
</component>
</project>

9
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectKey">
<option name="state" value="project://e79810c8-c5c8-43b1-b19c-90c1f4095425" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" default="false" project-jdk-name="9-ea" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Symmie.iml" filepath="$PROJECT_DIR$/Symmie.iml" />
</modules>
</component>
</project>

125
.idea/uiDesigner.xml generated Normal file
View File

@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

7
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>

BIN
JavaFXApp.jar Normal file

Binary file not shown.

12
Symmie.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

1
destination/Moar.txt Normal file

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
Hello Symmie!

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,38 @@
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

1
source/Moar.txt Normal file

File diff suppressed because one or more lines are too long

1
source/SymmieTest.txt Normal file
View File

@ -0,0 +1 @@
Hello Symmie!

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,38 @@
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf
asdfasdfasdfadf

File diff suppressed because one or more lines are too long

1
source/asdfasdfasdf.txt Normal file

File diff suppressed because one or more lines are too long

3
src/META-INF/MANIFEST.MF Normal file
View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: net.tofvesson.symlinker.Main

View File

@ -0,0 +1,4 @@
package net.tofvesson.symlinker;
public class Controller {
}

View File

@ -0,0 +1,113 @@
package net.tofvesson.symlinker;
import java.io.*;
import java.math.BigInteger;
/** @noinspection WeakerAccess, ConstantConditions, unused */
public class FileMover {
public static final int DEFAULT_BUFFER_SIZE = 8192;
public static final int MINIMUM_BUFFER_SIZE = 256;
protected volatile boolean cancel = false;
protected volatile BigInteger currentTransferSize = BigInteger.ZERO;
protected final Thread moveOp;
protected final FileMoveErrorHandler handler;
protected final BigInteger totalSize;
protected final int bufferSize;
public FileMover(File source, File destination, int bufferSize, FileMoveErrorHandler errorHandler){
handler = errorHandler;
this.bufferSize = bufferSize < MINIMUM_BUFFER_SIZE ? bufferSize : DEFAULT_BUFFER_SIZE;
totalSize = enumerate(source, BigInteger.ZERO);
moveOp = new Thread(()->{
if(!destination.isDirectory()) if(!destination.mkdirs()){
if(handler!=null) handler.onMoveError(source, destination);
System.err.println("Couldn't create necessary directories!");
return;
}
if(totalSize.subtract(BigInteger.valueOf(destination.getUsableSpace())).toString().charAt(0)!='-'){
if(handler!=null) handler.onMoveError(source, destination);
System.err.println("Not enough space in destination to accommodate move operation!");
return;
}
moveAll(source, destination, true);
if(!destroyDirs(source)) System.err.println("Could not delete source directories!");
System.out.println("Done!");
});
moveOp.setPriority(Thread.MAX_PRIORITY);
moveOp.start();
}
private static BigInteger enumerate(File f, BigInteger b){
if(f.isFile()) return b.add(BigInteger.valueOf(f.length()));
if(f.isDirectory()) for(File f1 : f.listFiles()) b = enumerate(f1, b);
return b;
}
public boolean isAlive(){ return moveOp.isAlive(); }
public BigInteger getTotalSize(){ return totalSize; }
public BigInteger getCurrentTransferSize(){ return currentTransferSize; }
public void cancel(){ cancel = true; }
public boolean isCanceling(){ return cancel && moveOp.isAlive(); }
public boolean isCanceled(){ return cancel && !moveOp.isAlive(); }
protected void moveAll(File source, File destDir, boolean first)
{
if(cancel) return; // Cancel requested: don't initiate more move operations
File f = first ? destDir : new File(destDir.getAbsolutePath()+File.separatorChar+source.getName());
if(source.isFile()) moveFile(source, f);
else if(source.isDirectory()){ // If-statement is here is safeguard in case something goes wrong and we try to move a non-existent file/folder
if(!f.mkdir() && handler!=null) handler.onMoveError(source, destDir);
for(File f1 : source.listFiles()){
if(cancel) break;
moveAll(f1, f, false);
}
}
}
protected boolean destroyDirs(File top){
boolean canDestroyMe = true;
if(top.isDirectory()) for(File f : top.listFiles()) canDestroyMe = destroyDirs(f) && canDestroyMe; // Must attempt to destroy directory!
return top.delete() && canDestroyMe;
}
protected void moveFile(File sourceFile, File destFile)
{
InputStream read = null;
OutputStream write = null;
try{
// ---- Error Handling ----
if(destFile.isFile() && !destFile.delete()){
if(handler!=null) handler.onMoveError(sourceFile, destFile);
throw new Exception("Can't delete existing file: "+destFile.getAbsolutePath());
}
if(!destFile.createNewFile()){ // Make sure we actually have a file to write to
if(handler!=null) handler.onMoveError(sourceFile, destFile);
throw new Exception("Can't create file: "+destFile.getAbsolutePath());
}
// ---- Prepare move operation ----
read = new FileInputStream(sourceFile);
write = new FileOutputStream(destFile);
byte[] dBuf = new byte[bufferSize];
int readLen;
// ---- Move data ----
while(read.available()>0){
readLen = read.read(dBuf);
write.write(dBuf, 0, readLen);
currentTransferSize = currentTransferSize.add(BigInteger.valueOf(readLen));
if(cancel) throw new Exception("Move operation from \""+sourceFile.getAbsolutePath()+"\" to \""+destFile.getAbsolutePath()+"\" was canceled!"); // Handle cancel
}
}catch(Throwable t){ t.printStackTrace(); if(!cancel && handler!=null) handler.onMoveError(sourceFile, destFile); } // Don't consider cancellation an error
finally {
if(read!=null) try { read.close(); } catch (IOException e) { e.printStackTrace(); } // Ultimate errors are happening if this is thrown
if(write!=null) try { write.close(); } catch (IOException e) { e.printStackTrace(); } // Ultimate errors are happening if this is thrown
if(!cancel && !sourceFile.delete()) System.err.println("Can't delete source file: "+sourceFile.getAbsolutePath()); // Handle regular move event
if(cancel && !destFile.delete()) System.err.println("Can't delete destination file: "+destFile.getAbsolutePath()); // Handle cancel event
}
}
public interface FileMoveErrorHandler { void onMoveError(File sourceFile, File destinationFile); }
}

View File

@ -0,0 +1,70 @@
package net.tofvesson.symlinker;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.prefs.Preferences;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) throws Throwable {
if(!isAdmin()){
System.out.println("Not admin");
System.exit(-1);
}
File source = new File(System.getProperty("user.dir")+File.separatorChar+"source"+File.separatorChar),
destination = new File(System.getProperty("user.dir")+File.separatorChar+"destination"+File.separatorChar);
moveAndLink(source, destination);
launch(args);
}
protected static void moveAndLink(File source, File destination) throws IOException, InterruptedException {
boolean dir = source.isDirectory();
FileMover mover = new FileMover(source, destination, FileMover.DEFAULT_BUFFER_SIZE, null);
while(mover.isAlive()){
System.out.println("Move progress: "+(mover.getCurrentTransferSize().doubleValue()/mover.getTotalSize().doubleValue())*100+"%");
try { Thread.sleep(1); }catch(InterruptedException ignored){}
}
System.out.println("Move progress: 100%");
//try { Thread.sleep(25); }catch(InterruptedException ignored){} // Shouldn't be necessary
Runtime.getRuntime().exec("cmd /c \"mklink "+(dir ? "/J " : "")+"\""+source.getAbsolutePath()+"\" \""+destination.getAbsolutePath()+"\"\"");
}
public static boolean isAdmin(){
PrintStream o = System.err;
// Silent error stream because not explicitly printing errors isn't enough to stop errors from being printed
System.setErr(new PrintStream(new OutputStream() { @Override public void write(int i) throws IOException { } }));
Preferences prefs = Preferences.systemRoot();
try{
prefs.put("foo", "bar"); // SecurityException on Windows
prefs.remove("foo");
prefs.flush(); // BackingStoreException on Linux
return true;
}catch(Exception e){
return false;
}finally{ System.setErr(o); }
}
}

View File

@ -0,0 +1,8 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="net.tofvesson.symlinker.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>