mirror of
https://github.com/workinghard/GuitarTeX2.git
synced 2025-12-13 18:32:09 +00:00
New GTX client due to server rework
This commit is contained in:
10
.classpath
10
.classpath
@@ -9,6 +9,7 @@
|
|||||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
@@ -36,6 +37,13 @@
|
|||||||
<attribute name="m2e-apt" value="true"/>
|
<attribute name="m2e-apt" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="test" value="true"/>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
|
|||||||
4
.project
4
.project
@@ -22,12 +22,12 @@
|
|||||||
</natures>
|
</natures>
|
||||||
<filteredResources>
|
<filteredResources>
|
||||||
<filter>
|
<filter>
|
||||||
<id>1641408443802</id>
|
<id>1720116449156</id>
|
||||||
<name></name>
|
<name></name>
|
||||||
<type>30</type>
|
<type>30</type>
|
||||||
<matcher>
|
<matcher>
|
||||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
</matcher>
|
</matcher>
|
||||||
</filter>
|
</filter>
|
||||||
</filteredResources>
|
</filteredResources>
|
||||||
|
|||||||
85
pom.xml
85
pom.xml
@@ -6,23 +6,31 @@
|
|||||||
|
|
||||||
<groupId>guitartex2.GuitarTeX2</groupId>
|
<groupId>guitartex2.GuitarTeX2</groupId>
|
||||||
<artifactId>GuitarTeX2</artifactId>
|
<artifactId>GuitarTeX2</artifactId>
|
||||||
<version>3.5.0</version>
|
<version>3.6.0</version>
|
||||||
|
|
||||||
<name>GuitarTeX2</name>
|
<name>GuitarTeX2</name>
|
||||||
<url></url>
|
<url></url>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<!--<maven.compiler.source>1.9</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.9</maven.compiler.target> -->
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20240303</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
|
||||||
<configuration>
|
<configuration>
|
||||||
<descriptorRefs>
|
<descriptorRefs>
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
@@ -47,77 +55,13 @@
|
|||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<version>3.1.1</version>
|
|
||||||
<configuration>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>guitartex2.GuitarTeX2Convert</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<finalName>${project.artifactId}Convert-${project.version}</finalName>
|
|
||||||
<appendAssemblyId>false</appendAssemblyId>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>make-assembly</id>
|
|
||||||
<!-- bind to the packaging phase -->
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<argLine>${argLine}</argLine>
|
<argLine>${argLine}</argLine>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.jacoco</groupId>
|
|
||||||
<artifactId>jacoco-maven-plugin</artifactId>
|
|
||||||
<version>0.8.3</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>prepare-agent</id>
|
|
||||||
<goals>
|
|
||||||
<goal>prepare-agent</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>report</id>
|
|
||||||
<phase>prepare-package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>post-unit-test</id>
|
|
||||||
<phase>test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>report</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<dataFile>target/jacoco.exec</dataFile>
|
|
||||||
<outputDirectory>target/jacoco-ut</outputDirectory>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -134,6 +78,9 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.0</version>
|
<version>3.8.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>11</release> <!--or <release>10</release>-->
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
|||||||
@@ -402,7 +402,17 @@ final class Configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getGtxServerPort() {
|
public int getGtxServerPort() {
|
||||||
return Integer.parseInt(mProperties.getProperty("gtxServerPort"));
|
int serverPort = -1;
|
||||||
|
try {
|
||||||
|
serverPort = Integer.parseInt(mProperties.getProperty("gtxServerPort"));
|
||||||
|
}catch (Exception e) {
|
||||||
|
// It's fine to have empty field
|
||||||
|
}
|
||||||
|
if ( serverPort > 0 ) {
|
||||||
|
return serverPort;
|
||||||
|
}else{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGtxServerPort(String mValue) {
|
public void setGtxServerPort(String mValue) {
|
||||||
|
|||||||
@@ -1,303 +0,0 @@
|
|||||||
/*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package guitartex2;
|
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.RandomAccessFile;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
import java.util.zip.GZIPOutputStream;
|
|
||||||
|
|
||||||
class FileTransfer {
|
|
||||||
|
|
||||||
// Debug 0/1
|
|
||||||
int debug = 0;
|
|
||||||
|
|
||||||
// Define commands
|
|
||||||
//private static String quit = "CMD:123_QUIT_123";
|
|
||||||
//private static String transfer = "CMD:123_TRANSFER_123";
|
|
||||||
private static String ok = "CMD:123_OK_123";
|
|
||||||
private static String failed = "CMD:123_FAILED_123";
|
|
||||||
|
|
||||||
// Father ID
|
|
||||||
int fId;
|
|
||||||
|
|
||||||
// Streams
|
|
||||||
DataInputStream inStream;
|
|
||||||
DataOutputStream outStream;
|
|
||||||
|
|
||||||
// Main - Constructor
|
|
||||||
public FileTransfer(int id, DataInputStream inputStream, DataOutputStream outputStream) {
|
|
||||||
fId = id;
|
|
||||||
inStream = inputStream;
|
|
||||||
outStream = outputStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileTransfer(int id, int mDebug, DataInputStream inputStream, DataOutputStream outputStream) {
|
|
||||||
debug = mDebug;
|
|
||||||
fId = id;
|
|
||||||
inStream = inputStream;
|
|
||||||
outStream = outputStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("UnusedAssignment")
|
|
||||||
public int sendFile(String myFile) {
|
|
||||||
RandomAccessFile in;
|
|
||||||
|
|
||||||
long length;
|
|
||||||
String fileLengthResult;
|
|
||||||
|
|
||||||
int zipResult = gzipFile(myFile, false);
|
|
||||||
if (zipResult == 0) {
|
|
||||||
myFile = myFile + ".gz";
|
|
||||||
} else {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: can't gzip file");
|
|
||||||
try {
|
|
||||||
outStream.writeInt(0);
|
|
||||||
fileLengthResult = inStream.readUTF();
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error" + e);
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
in = new RandomAccessFile(myFile, "r");
|
|
||||||
length = in.length();
|
|
||||||
} catch (Exception g) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: can't read file" + g);
|
|
||||||
try {
|
|
||||||
outStream.writeInt(0);
|
|
||||||
fileLengthResult = inStream.readUTF();
|
|
||||||
} catch (Exception h) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error" + h);
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (length > Integer.MAX_VALUE) {
|
|
||||||
// File is too large
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: File is too large");
|
|
||||||
cleanTmp(myFile, in);
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
int myFileLength = (int) length;
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: sending fille length: " + myFileLength);
|
|
||||||
try {
|
|
||||||
outStream.writeInt(myFileLength);
|
|
||||||
fileLengthResult = inStream.readUTF();
|
|
||||||
} catch (Exception i) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error" + i);
|
|
||||||
cleanTmp(myFile, in);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (fileLengthResult.equals(ok)) {
|
|
||||||
try {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: send a file...");
|
|
||||||
byte b;
|
|
||||||
for (int i = 0; i < myFileLength; i++) {
|
|
||||||
b = in.readByte();
|
|
||||||
outStream.writeByte(b);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
File f = new File(myFile);
|
|
||||||
f.delete();
|
|
||||||
String fileTransferResult = inStream.readUTF();
|
|
||||||
if (fileTransferResult.equals(failed)) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: sending file failed: " + fileTransferResult);
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} catch (Exception j) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error" + j);
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: sending file length failed: " + fileLengthResult);
|
|
||||||
cleanTmp(myFile, in);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int receiveFile(String myFile) {
|
|
||||||
int fileLength;
|
|
||||||
RandomAccessFile out;
|
|
||||||
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: awaiting filelength ...");
|
|
||||||
try {
|
|
||||||
fileLength = inStream.readInt();
|
|
||||||
} catch (IOException e) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error " + e);
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: file length = " + fileLength);
|
|
||||||
if (fileLength > 0) {
|
|
||||||
try {
|
|
||||||
out = new RandomAccessFile(myFile + ".gz", "rw");
|
|
||||||
} catch (IOException g) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: can't write to a file " + g);
|
|
||||||
try {
|
|
||||||
outStream.writeUTF(failed);
|
|
||||||
} catch (Exception h) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error " + h);
|
|
||||||
}
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
outStream.writeUTF(ok);
|
|
||||||
} catch (Exception i) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error " + i);
|
|
||||||
cleanTmp(myFile, out);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: awaiting file...");
|
|
||||||
try {
|
|
||||||
byte b;
|
|
||||||
for (int i = 0; i < fileLength; i++) {
|
|
||||||
b = inStream.readByte();
|
|
||||||
out.write(b);
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
} catch (Exception j) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: file transfer failed " + j);
|
|
||||||
try {
|
|
||||||
outStream.writeUTF(failed);
|
|
||||||
} catch (Exception k) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error " + k);
|
|
||||||
}
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
outStream.writeUTF(ok);
|
|
||||||
int gunzipResult = gunzipFile(myFile + ".gz", true);
|
|
||||||
if (gunzipResult != 0) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: gunzip failed");
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} catch (Exception l) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: stream error " + l);
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: file transfer complete.");
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
outStream.writeUTF(failed);
|
|
||||||
} catch (Exception f) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: file length invalid");
|
|
||||||
cleanTmp(myFile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int gzipFile(String myFile, boolean delSource) {
|
|
||||||
int read;
|
|
||||||
byte[] data = new byte[1024];
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: gzip file");
|
|
||||||
try {
|
|
||||||
File f = new File(myFile);
|
|
||||||
GZIPOutputStream out;
|
|
||||||
try (FileInputStream in = new FileInputStream(f)) {
|
|
||||||
out = new GZIPOutputStream(new FileOutputStream(myFile + ".gz"));
|
|
||||||
while ((read = in.read(data, 0, 1024)) != -1) {
|
|
||||||
out.write(data, 0, read);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
if (delSource == true) {
|
|
||||||
f.delete();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: gzipping file failed " + e);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: gzip file");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int gunzipFile(String myGZFile, boolean delSource) {
|
|
||||||
int read;
|
|
||||||
byte[] data = new byte[1024];
|
|
||||||
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: gunzip file");
|
|
||||||
|
|
||||||
try {
|
|
||||||
File f = new File(myGZFile);
|
|
||||||
FileOutputStream out;
|
|
||||||
try (GZIPInputStream in = new GZIPInputStream(new FileInputStream(f))) {
|
|
||||||
String myFile;
|
|
||||||
if (myGZFile.endsWith(".gz")) {
|
|
||||||
myFile = myGZFile.substring(0, myGZFile.length() - 3);
|
|
||||||
} else {
|
|
||||||
myFile = myGZFile;
|
|
||||||
} out = new FileOutputStream(myFile);
|
|
||||||
while ((read = in.read(data, 0, 1024)) != -1) {
|
|
||||||
out.write(data, 0, read);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.close();
|
|
||||||
if (delSource == true) {
|
|
||||||
f.delete();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendMsg("Filetransfer[" + fId + "]: gunzipping file failed " + e);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendMsg(String msg) {
|
|
||||||
if (debug == 1) {
|
|
||||||
System.out.println(msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cleanTmp(String fileName, RandomAccessFile file) {
|
|
||||||
try {
|
|
||||||
new File(fileName).delete();
|
|
||||||
file.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendMsg("can't clean tmp file: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cleanTmp(String fileName) {
|
|
||||||
try {
|
|
||||||
new File(fileName).delete();
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendMsg("can't clean tmp file: " + e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,77 +16,67 @@
|
|||||||
|
|
||||||
package guitartex2;
|
package guitartex2;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.io.*;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
|
|
||||||
public class GTXClient extends Thread{
|
public class GTXClient extends Thread{
|
||||||
|
|
||||||
|
private StatusBox _myStatusBox;
|
||||||
|
private String _texFileName;
|
||||||
|
private String _pdfFileName;
|
||||||
|
private String _showPdf;
|
||||||
|
|
||||||
private static String quit = "CMD:123_QUIT_123";
|
private boolean _hostExist = false;
|
||||||
private static String transfer = "CMD:123_TRANSFER_123";
|
|
||||||
//private static String ok = "CMD:123_OK_123";
|
|
||||||
private static String failed = "CMD:123_FAILED_123";
|
|
||||||
private static String ping = "CMD:123_PING_123";
|
|
||||||
private static String pong = "CMD:123_PONG_123";
|
|
||||||
|
|
||||||
private int id;
|
private ResourceBundle _resbundle;
|
||||||
private StatusBox myStatusBox;
|
|
||||||
private String fileName;
|
|
||||||
private String showPdf;
|
|
||||||
|
|
||||||
private boolean hostExist = false;
|
|
||||||
|
|
||||||
private ResourceBundle resbundle;
|
private GTXConsole _myConsole;
|
||||||
protected Socket serverConn;
|
|
||||||
DataOutputStream dout;
|
|
||||||
DataInputStream din;
|
|
||||||
|
|
||||||
private GTXConsole myConsole;
|
|
||||||
private String logCache = "";
|
private String logCache = "";
|
||||||
|
private String _urlPingEndpoint = "/ping";
|
||||||
|
private String _urlLatexEndpoint = "/latex";
|
||||||
|
private String _httpsURLPing = "";
|
||||||
|
private String _httpsURLLatex = "";
|
||||||
|
|
||||||
// Konstruktor
|
// Konstruktor
|
||||||
public GTXClient(String host, int port) {
|
public GTXClient(String host, int port) {
|
||||||
resbundle = ResourceBundle.getBundle ("GuitarTeX2strings", Locale.getDefault());
|
_resbundle = ResourceBundle.getBundle ("GuitarTeX2strings", Locale.getDefault());
|
||||||
try {
|
if ( port > 0) {
|
||||||
logToConsole("Trying to connect to " + host + " " + port);
|
_httpsURLPing = host + ":" + port + _urlPingEndpoint;
|
||||||
serverConn = new Socket(host, port);
|
_httpsURLLatex = host + ":" + port + _urlLatexEndpoint;
|
||||||
}catch (UnknownHostException e) {
|
}else{
|
||||||
logToConsole("Bad host name given.");
|
_httpsURLPing = host + _urlPingEndpoint;
|
||||||
}catch (IOException e) {
|
_httpsURLLatex = host + _urlLatexEndpoint;
|
||||||
logToConsole("GtxClient: " + e);
|
}
|
||||||
|
logToConsole("PingURL: " + _httpsURLPing);
|
||||||
|
logToConsole("LatexURL: " + _httpsURLLatex);
|
||||||
|
int available = this.checkServerConnection();
|
||||||
|
if ( available == 0 ) {
|
||||||
|
_hostExist = true;
|
||||||
|
logToConsole("Made server connection");
|
||||||
|
}else{
|
||||||
|
_hostExist = false;
|
||||||
|
logToConsole("No server connection");
|
||||||
}
|
}
|
||||||
hostExist = true;
|
|
||||||
logToConsole("Made server connection");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GTXClient(String host, int port, StatusBox sBox, String file, int myId, String sPdf) {
|
public GTXClient(String host, int port, StatusBox sBox, String texFile, String pdfFile, String sPdf) {
|
||||||
resbundle = ResourceBundle.getBundle ("GuitarTeX2strings", Locale.getDefault());
|
this(host, port);
|
||||||
try {
|
|
||||||
logToConsole("Trying to connect to " + host + " " + port);
|
|
||||||
serverConn = new Socket(host, port);
|
|
||||||
}catch (UnknownHostException e) {
|
|
||||||
logToConsole("Bad host name given.");
|
|
||||||
}catch (IOException e) {
|
|
||||||
logToConsole("GtxClient: " + e);
|
|
||||||
}
|
|
||||||
|
|
||||||
hostExist = true;
|
_showPdf = sPdf;
|
||||||
showPdf = sPdf;
|
_myStatusBox = sBox;
|
||||||
id = myId;
|
_texFileName = texFile;
|
||||||
myStatusBox = sBox;
|
_pdfFileName = pdfFile;
|
||||||
fileName = file;
|
|
||||||
|
|
||||||
logToConsole("Made server connection");
|
logToConsole("Made server connection");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void logToConsole(String text) {
|
private void logToConsole(String text) {
|
||||||
if ( myConsole == null ) {
|
if ( _myConsole == null ) {
|
||||||
if ( logCache.equals("") ) {
|
if ( logCache.equals("") ) {
|
||||||
logCache = text;
|
logCache = text;
|
||||||
}else{
|
}else{
|
||||||
@@ -94,32 +84,86 @@ public class GTXClient extends Thread{
|
|||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if ( ! logCache.equals("") ) {
|
if ( ! logCache.equals("") ) {
|
||||||
myConsole.addText(logCache);
|
_myConsole.addText(logCache);
|
||||||
logCache = "";
|
logCache = "";
|
||||||
myConsole.addText(text);
|
_myConsole.addText(text);
|
||||||
}else{
|
}else{
|
||||||
myConsole.addText(text);
|
_myConsole.addText(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGTXConsole(GTXConsole mConsole) {
|
void setGTXConsole(GTXConsole mConsole) {
|
||||||
myConsole = mConsole;
|
_myConsole = mConsole;
|
||||||
if ( ! logCache.equals("") ) {
|
if ( ! logCache.equals("") ) {
|
||||||
myConsole.addText(logCache);
|
_myConsole.addText(logCache);
|
||||||
logCache = "";
|
logCache = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void forceLogCache() {
|
void forceLogCache() {
|
||||||
if ( myConsole != null ) {
|
if ( _myConsole != null ) {
|
||||||
myConsole.addText(logCache);
|
_myConsole.addText(logCache);
|
||||||
logCache = null;
|
logCache = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run () {
|
||||||
|
// Do something only if the connection exist
|
||||||
|
if ( _hostExist == true ) {
|
||||||
|
if ( _myStatusBox != null ) {
|
||||||
|
_myStatusBox.setStatus(_resbundle.getString("sendTexFile"));
|
||||||
|
}
|
||||||
|
logToConsole("Sending tex file...");
|
||||||
|
try {
|
||||||
|
ServerResponse myResponse = MultipartFormSender.sendMultipartForm(_httpsURLLatex, _texFileName,
|
||||||
|
"file", "text", "{\"version\":\"1.0\"}");
|
||||||
|
logToConsole(myResponse.toString());
|
||||||
|
if ( myResponse.isInitial() == false ) {
|
||||||
|
if ( myResponse.getCmdRC() == 0 ) {
|
||||||
|
if ( myResponse.getDownloadURL() != "" ) {
|
||||||
|
_myStatusBox.setStatus(_resbundle.getString("receivePdfFile"));
|
||||||
|
// Download file
|
||||||
|
BufferedInputStream in = new BufferedInputStream(new URL(myResponse.getDownloadURL()).openStream());
|
||||||
|
FileOutputStream fileOutputStream = new FileOutputStream(_pdfFileName);
|
||||||
|
byte dataBuffer[] = new byte[1024];
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
|
||||||
|
fileOutputStream.write(dataBuffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
fileOutputStream.close();
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
logToConsole("pdf file received.");
|
||||||
|
// Show PDF
|
||||||
|
_myStatusBox.setStatus("try to show PDF file ...");
|
||||||
|
logToConsole("try to show pdf file");
|
||||||
|
try{
|
||||||
|
Runtime.getRuntime().exec(_showPdf);
|
||||||
|
}catch (Exception h) {
|
||||||
|
logToConsole("ERR: " + h);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
logToConsole("Download URL is missing");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
logToConsole("Tex command failed");
|
||||||
|
new InfoBox(_resbundle.getString("texFailed"));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
logToConsole("Got no response from server");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logToConsole("tex file send failed: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
logToConsole("We're offline. Please check internet connection");
|
||||||
|
}
|
||||||
|
|
||||||
|
_myStatusBox.setVisible(false);
|
||||||
|
|
||||||
|
/*
|
||||||
try {
|
try {
|
||||||
if ( myStatusBox != null ) {
|
if ( myStatusBox != null ) {
|
||||||
myStatusBox.setStatus(resbundle.getString("sendTexFile"));
|
myStatusBox.setStatus(resbundle.getString("sendTexFile"));
|
||||||
@@ -171,87 +215,38 @@ public class GTXClient extends Thread{
|
|||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
logToConsole("failed texin file: " + e);
|
logToConsole("failed texin file: " + e);
|
||||||
}
|
}
|
||||||
}
|
*/
|
||||||
|
|
||||||
public int openConnection() {
|
|
||||||
if ( hostExist) {
|
|
||||||
try {
|
|
||||||
dout = new DataOutputStream(serverConn.getOutputStream());
|
|
||||||
din = new DataInputStream(serverConn.getInputStream());
|
|
||||||
logToConsole("connection open");
|
|
||||||
return 0;
|
|
||||||
}catch (Exception e) {
|
|
||||||
logToConsole("open connection failed: " + e);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
logToConsole("Host not exists!");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int closeConnection() {
|
|
||||||
if ( hostExist ) {
|
|
||||||
try {
|
|
||||||
dout.writeUTF(quit);
|
|
||||||
din.close();
|
|
||||||
dout.close();
|
|
||||||
logToConsole("connection closed");
|
|
||||||
return 0;
|
|
||||||
}catch (Exception e) {
|
|
||||||
logToConsole("close connection failed: " + e);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
logToConsole("Host not exists!");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int checkServerConnection() {
|
public int checkServerConnection() {
|
||||||
if ( hostExist ) {
|
try{
|
||||||
try {
|
URL myUrl = new URL(_httpsURLPing);
|
||||||
logToConsole("sending ping ...");
|
HttpsURLConnection conn = (HttpsURLConnection)myUrl.openConnection();
|
||||||
dout.writeUTF(ping);
|
if ( conn.getResponseCode() == 200 ) {
|
||||||
logToConsole("awaiting pong ...");
|
return 0;
|
||||||
String pingResult = din.readUTF();
|
}else{
|
||||||
logToConsole(pingResult);
|
logToConsole("responseCode: " + conn.getResponseCode());
|
||||||
if ( pingResult.equals(pong)) {
|
InputStream is = conn.getInputStream();
|
||||||
logToConsole("pong received.");
|
InputStreamReader isr = new InputStreamReader(is);
|
||||||
return 0;
|
BufferedReader br = new BufferedReader(isr);
|
||||||
}else {
|
String inputLine;
|
||||||
logToConsole("server doesn't working.");
|
String bodeString = "";
|
||||||
return 1;
|
while ((inputLine = br.readLine()) != null) {
|
||||||
}
|
bodeString = bodeString + inputLine;
|
||||||
}catch (Exception e) {
|
}
|
||||||
logToConsole("ping failed " + e);
|
br.close();
|
||||||
return 1;
|
logToConsole("Error: " + bodeString);
|
||||||
}
|
return 1;
|
||||||
}else{
|
}
|
||||||
logToConsole("Host not exists!");
|
}catch (Exception e) {
|
||||||
return 1;
|
logToConsole("Error: " + e.getMessage());
|
||||||
}
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendText(String text) {
|
public String sendText(String text) {
|
||||||
String result = "unknown command!";
|
String result = "not implemented yet!";
|
||||||
if ( text.equals("ping") ){
|
|
||||||
try {
|
|
||||||
dout.writeUTF(ping);
|
|
||||||
result = din.readUTF();
|
|
||||||
if ( result.equals(pong) ) {
|
|
||||||
result = "pong";
|
|
||||||
}
|
|
||||||
dout.writeUTF(quit);
|
|
||||||
}catch (Exception e) {
|
|
||||||
logToConsole("Sending failed!");
|
|
||||||
return "Sending failed!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
/* public int tex2pdf(String fileName, int id) {
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -142,15 +142,11 @@ class GTXConsole extends JFrame implements ActionListener{
|
|||||||
public void setGTXClient(Configurations mConf) {
|
public void setGTXClient(Configurations mConf) {
|
||||||
myConf = mConf;
|
myConf = mConf;
|
||||||
gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort());
|
gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort());
|
||||||
int openResult = gtxClient.openConnection();
|
int connResult = gtxClient.checkServerConnection();
|
||||||
if ( openResult == 0 ) {
|
if ( connResult == 0) {
|
||||||
int connResult = gtxClient.checkServerConnection();
|
mInputButton.setEnabled(true);
|
||||||
if ( connResult == 0) {
|
mInputAction.setEnabled(true);
|
||||||
mInputButton.setEnabled(true);
|
|
||||||
mInputAction.setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gtxClient.closeConnection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class buttonActionClass extends AbstractAction {
|
public class buttonActionClass extends AbstractAction {
|
||||||
@@ -170,12 +166,11 @@ class GTXConsole extends JFrame implements ActionListener{
|
|||||||
|
|
||||||
// Nachricht senden
|
// Nachricht senden
|
||||||
gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort());
|
gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort());
|
||||||
int openResult = gtxClient.openConnection();
|
int checkResult = gtxClient.checkServerConnection();
|
||||||
if ( openResult == 0 ) {
|
if ( checkResult == 0 ) {
|
||||||
String receiveText = gtxClient.sendText(mInputTextField.getText());
|
String receiveText = gtxClient.sendText(mInputTextField.getText());
|
||||||
addText("Server: " + receiveText);
|
addText("Server: " + receiveText);
|
||||||
}
|
}
|
||||||
gtxClient.closeConnection();
|
|
||||||
|
|
||||||
mInputTextField.setText("");
|
mInputTextField.setText("");
|
||||||
mInputTextField.requestFocus();
|
mInputTextField.requestFocus();
|
||||||
|
|||||||
@@ -284,15 +284,11 @@ public class GuitarTeX2 extends JFrame {
|
|||||||
|
|
||||||
GTXClient gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort());
|
GTXClient gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort());
|
||||||
gtxClient.setGTXConsole(consoleBox);
|
gtxClient.setGTXConsole(consoleBox);
|
||||||
int openResult = gtxClient.openConnection();
|
int connResult = gtxClient.checkServerConnection();
|
||||||
if (openResult == 0) {
|
if (connResult == 0) {
|
||||||
int connResult = gtxClient.checkServerConnection();
|
mTeX2PdfButton.setEnabled(true);
|
||||||
if (connResult == 0) {
|
mTeX2PdfAction.setEnabled(true);
|
||||||
mTeX2PdfButton.setEnabled(true);
|
|
||||||
mTeX2PdfAction.setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
gtxClient.closeConnection();
|
|
||||||
|
|
||||||
// Create StatusBox
|
// Create StatusBox
|
||||||
myStatusBox = new StatusBox();
|
myStatusBox = new StatusBox();
|
||||||
@@ -1175,13 +1171,14 @@ public class GuitarTeX2 extends JFrame {
|
|||||||
try (OutputStreamWriter out = new OutputStreamWriter(fos, Charset.forName("UTF-8"))) {
|
try (OutputStreamWriter out = new OutputStreamWriter(fos, Charset.forName("UTF-8"))) {
|
||||||
out.write(mShowTeXArea.getText());
|
out.write(mShowTeXArea.getText());
|
||||||
//if ( mShowTeXArea.isEnabled() ) {
|
//if ( mShowTeXArea.isEnabled() ) {
|
||||||
String showPdf = myConf.quoteString(myConf.getPdfViewer()) + " " + myConf.quoteString(tmpDir + tmpDirPrefix + pdfFileName);
|
String pdfFileNamePath = tmpDir + tmpDirPrefix + pdfFileName;
|
||||||
GTXClient gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort(), myStatusBox, tmpDir + tmpDirPrefix + texFileName, id, showPdf);
|
String showPdf = myConf.quoteString(myConf.getPdfViewer()) + " " + myConf.quoteString(pdfFileNamePath);
|
||||||
|
GTXClient gtxClient = new GTXClient(myConf.getGtxServer(), myConf.getGtxServerPort(), myStatusBox, tmpDir + tmpDirPrefix + texFileName, pdfFileNamePath, showPdf);
|
||||||
gtxClient.setGTXConsole(consoleBox);
|
gtxClient.setGTXConsole(consoleBox);
|
||||||
int openResult = gtxClient.openConnection();
|
//int checkResult = gtxClient.checkServerConnection();
|
||||||
if (openResult == 0) {
|
//if (checkResult == 0) {
|
||||||
gtxClient.start();
|
gtxClient.start();
|
||||||
}
|
//}
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
} catch (Exception g) {
|
} catch (Exception g) {
|
||||||
|
|||||||
98
src/main/java/guitartex2/MultipartFormSender.java
Normal file
98
src/main/java/guitartex2/MultipartFormSender.java
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
package guitartex2;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public class MultipartFormSender {
|
||||||
|
|
||||||
|
public static ServerResponse sendMultipartForm(String requestURL, String filePath, String fileFormFieldName, String fieldName, String fieldValue) throws IOException {
|
||||||
|
String boundary = "*****"+Long.toString(System.currentTimeMillis())+"*****";
|
||||||
|
String lineEnd = "\r\n";
|
||||||
|
String twoHyphens = "--";
|
||||||
|
ServerResponse myResponse = new ServerResponse();
|
||||||
|
|
||||||
|
URL url = new URL(requestURL);
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setUseCaches(false);
|
||||||
|
connection.setDoOutput(true); // Indicates POST method
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setRequestProperty("Connection", "Keep-Alive");
|
||||||
|
connection.setRequestProperty("User-Agent", "GuitarTex2 v3.5");
|
||||||
|
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
|
||||||
|
|
||||||
|
try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
|
||||||
|
// Write form fields
|
||||||
|
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
|
||||||
|
outputStream.writeBytes("Content-Disposition: form-data; name=\"" + fieldName + "\"" + lineEnd + lineEnd);
|
||||||
|
outputStream.writeBytes(fieldValue + lineEnd);
|
||||||
|
|
||||||
|
|
||||||
|
// Write file
|
||||||
|
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
|
||||||
|
outputStream.writeBytes("Content-Disposition: form-data; name=\"" + fileFormFieldName + "\"; filename=\"" + new File(filePath).getName() + "\"\r\n");
|
||||||
|
// Ensure the file part has an appropriate Content-Type, if necessary
|
||||||
|
outputStream.writeBytes("Content-Type: application/octet-stream\r\n\r\n");
|
||||||
|
try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(filePath))) {
|
||||||
|
byte[] buffer = new byte[8192]; // Consider adjusting the buffer size
|
||||||
|
int bytesRead;
|
||||||
|
while ((bytesRead = fileStream.read(buffer)) != -1) {
|
||||||
|
outputStream.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
outputStream.writeBytes("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// End of multipart/form-data.
|
||||||
|
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle the response from the server
|
||||||
|
int responseCode = connection.getResponseCode();
|
||||||
|
myResponse.setUrlRC(responseCode);
|
||||||
|
//System.out.println("Response Code: " + responseCode);
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
|
||||||
|
String line;
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
response.append(line);
|
||||||
|
response.append(System.lineSeparator());
|
||||||
|
}
|
||||||
|
// Try to decode the response
|
||||||
|
//JsonObject jsonObject = Json.createReader(new InputStream()).readObject();
|
||||||
|
|
||||||
|
JSONObject myJsonObject = new JSONObject(response.toString());
|
||||||
|
myResponse.setCmdRC(myJsonObject.getInt("cmd_rc"));
|
||||||
|
myResponse.setMsg(myJsonObject.getString("msg"));
|
||||||
|
myResponse.setDownloadURL(myJsonObject.getString("download_url"));
|
||||||
|
|
||||||
|
//myResponse.setMsg();
|
||||||
|
//System.out.println("Response: " + response.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("Json failed: " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
return myResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -165,7 +165,10 @@ public class PreferencesBox extends JFrame implements ActionListener {
|
|||||||
JLabel mGtxServerPortLabel = new JLabel(resbundle.getString("mPrefGtxServerPort"), JLabel.TRAILING);
|
JLabel mGtxServerPortLabel = new JLabel(resbundle.getString("mPrefGtxServerPort"), JLabel.TRAILING);
|
||||||
p.add(mGtxServerPortLabel);
|
p.add(mGtxServerPortLabel);
|
||||||
mGtxServerPortField = new JTextField(fieldLength);
|
mGtxServerPortField = new JTextField(fieldLength);
|
||||||
mGtxServerPortField.setText(Integer.toString(myConfiguration.getGtxServerPort()));
|
int portNr = myConfiguration.getGtxServerPort();
|
||||||
|
if ( portNr > 0 ) {
|
||||||
|
mGtxServerPortField.setText(Integer.toString(portNr));
|
||||||
|
}
|
||||||
mGtxServerPortLabel.setLabelFor(mGtxServerPortField);
|
mGtxServerPortLabel.setLabelFor(mGtxServerPortField);
|
||||||
p.add(mGtxServerPortField);
|
p.add(mGtxServerPortField);
|
||||||
p.add(new JLabel());
|
p.add(new JLabel());
|
||||||
@@ -283,7 +286,10 @@ public class PreferencesBox extends JFrame implements ActionListener {
|
|||||||
mPdfViewerField.setText(myConfiguration.getPdfViewer());
|
mPdfViewerField.setText(myConfiguration.getPdfViewer());
|
||||||
mTmpPathField.setText(myConfiguration.getTmpDir());
|
mTmpPathField.setText(myConfiguration.getTmpDir());
|
||||||
mGtxServerField.setText(myConfiguration.getGtxServer());
|
mGtxServerField.setText(myConfiguration.getGtxServer());
|
||||||
mGtxServerPortField.setText(myConfiguration.getGtxServerPort() + "");
|
int portNr = myConfiguration.getGtxServerPort();
|
||||||
|
if ( portNr > 0 ) {
|
||||||
|
mGtxServerPortField.setText(portNr + "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SymWindow extends java.awt.event.WindowAdapter {
|
class SymWindow extends java.awt.event.WindowAdapter {
|
||||||
@@ -306,17 +312,10 @@ public class PreferencesBox extends JFrame implements ActionListener {
|
|||||||
myConfiguration.saveSettings();
|
myConfiguration.saveSettings();
|
||||||
GTXClient gtxClient = new GTXClient(myConfiguration.getGtxServer(), myConfiguration.getGtxServerPort());
|
GTXClient gtxClient = new GTXClient(myConfiguration.getGtxServer(), myConfiguration.getGtxServerPort());
|
||||||
gtxClient.setGTXConsole(myConfiguration.getConsole());
|
gtxClient.setGTXConsole(myConfiguration.getConsole());
|
||||||
int openResult = gtxClient.openConnection();
|
int connResult = gtxClient.checkServerConnection();
|
||||||
if (openResult == 0) {
|
if (connResult == 0) {
|
||||||
int connResult = gtxClient.checkServerConnection();
|
tex2pdfButton.setEnabled(true);
|
||||||
if (connResult == 0) {
|
tex2pdfAction.setEnabled(true);
|
||||||
tex2pdfButton.setEnabled(true);
|
|
||||||
tex2pdfAction.setEnabled(true);
|
|
||||||
} else {
|
|
||||||
tex2pdfButton.setEnabled(false);
|
|
||||||
tex2pdfAction.setEnabled(false);
|
|
||||||
}
|
|
||||||
gtxClient.closeConnection();
|
|
||||||
} else {
|
} else {
|
||||||
tex2pdfButton.setEnabled(false);
|
tex2pdfButton.setEnabled(false);
|
||||||
tex2pdfAction.setEnabled(false);
|
tex2pdfAction.setEnabled(false);
|
||||||
|
|||||||
50
src/main/java/guitartex2/ServerResponse.java
Normal file
50
src/main/java/guitartex2/ServerResponse.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package guitartex2;
|
||||||
|
|
||||||
|
public class ServerResponse {
|
||||||
|
private int _urlRC = -1;
|
||||||
|
private int _cmdRC = -1;
|
||||||
|
private String _msg = "";
|
||||||
|
private String _downloadURL = "";
|
||||||
|
|
||||||
|
public int getUrlRC() {
|
||||||
|
return _urlRC;
|
||||||
|
}
|
||||||
|
public void setUrlRC(int urlRC) {
|
||||||
|
_urlRC = urlRC;
|
||||||
|
}
|
||||||
|
public int getCmdRC() {
|
||||||
|
return _cmdRC;
|
||||||
|
}
|
||||||
|
public void setCmdRC(int cmdRC) {
|
||||||
|
_cmdRC = cmdRC;
|
||||||
|
}
|
||||||
|
public String getMsg(){
|
||||||
|
return _msg;
|
||||||
|
}
|
||||||
|
public void setMsg(String msg){
|
||||||
|
_msg = msg;
|
||||||
|
}
|
||||||
|
public String getDownloadURL(){
|
||||||
|
return _downloadURL;
|
||||||
|
}
|
||||||
|
public void setDownloadURL(String downloadString ){
|
||||||
|
_downloadURL = downloadString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInitial(){
|
||||||
|
if ( _urlRC == -1 && _cmdRC == -1 && _msg == "" && _downloadURL == "" ) {
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder myresponse = new StringBuilder();
|
||||||
|
myresponse.append("urlRC: " + _urlRC + "\n");
|
||||||
|
myresponse.append("cmdRC: " + _cmdRC + "\n");
|
||||||
|
myresponse.append("msg: " + _msg + "\n");
|
||||||
|
myresponse.append("DownloadURL: " + _downloadURL + "\n");
|
||||||
|
return myresponse.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,5 +7,5 @@ windowsPdfViewer=/Programme/Adobe/Reader/AcroRd32.exe
|
|||||||
linuxPdfViewer=/usr/bin/xdg-open
|
linuxPdfViewer=/usr/bin/xdg-open
|
||||||
exSongFile=griechischer_wein.gtx
|
exSongFile=griechischer_wein.gtx
|
||||||
exBookFile=my_first_book.gtb
|
exBookFile=my_first_book.gtb
|
||||||
gtxServer=guitartex2.nikolai-rinas.de
|
gtxServer=https://latex2pdf.nikolai-rinas.de
|
||||||
gtxServerPort=3121
|
gtxServerPort=443
|
||||||
|
|||||||
@@ -128,5 +128,5 @@ warnTitle=Warning!
|
|||||||
statusTitle=Status
|
statusTitle=Status
|
||||||
|
|
||||||
frameConstructor=GuitarTeX2
|
frameConstructor=GuitarTeX2
|
||||||
appVersion=Version - 3.5.0
|
appVersion=Version - 3.6.0
|
||||||
copyright=Nikolai Rinas
|
copyright=Nikolai Rinas
|
||||||
|
|||||||
@@ -127,5 +127,5 @@ warnTitle=Warnung!
|
|||||||
statusTitle=Status
|
statusTitle=Status
|
||||||
|
|
||||||
frameConstructor=GuitarTeX2
|
frameConstructor=GuitarTeX2
|
||||||
appVersion=Version - 3.5.0
|
appVersion=Version - 3.6.0
|
||||||
copyright=Nikolai Rinas
|
copyright=Nikolai Rinas
|
||||||
Reference in New Issue
Block a user