String secretString = getSecretField();
String vaultString = getVaultField();
int regionInt = getServerRegion();
if (e.getSource() == newVaultButton && checkAWSFields()) {
AmazonGlacierClient newVaultClient = new AmazonGlacierClient();
newVaultClient = makeClient(accessString, secretString, regionInt);
AddVaultFrame avf = new AddVaultFrame(newVaultClient, regionInt);
avf.setVisible(true);
}
if (e.getSource() == vaultSelector) {
if (vaultSelector.getSelectedItem() != null) {
if (vaultSelector.getSelectedIndex() == 0) {
vaultField.setText("");
} else {
vaultField.setText(vaultSelector.getSelectedItem()
.toString());
}
} else {
}
}
if (e.getSource() == loginButton) {
repopulateVaults(accessString, secretString, regionInt);
}
if (e.getSource() == exitApplicationMnu) {
System.exit(0);
}
if (e.getSource() == updateMnu || e.getSource() == checkUpdateButton) {
JHyperlinkLabel.OpenURI(URL_STRING);
}
if (e.getSource() == saveFileMnu) {
FileDialog fd = new FileDialog(new Frame(), "Save...",
FileDialog.SAVE);
fd.setFile("Glacier.txt");
fd.setDirectory(curDir);
fd.setLocation(50, 50);
fd.setVisible(true);
// fd.show();
String filePath = "" + fd.getDirectory()
+ System.getProperty("file.separator") + fd.getFile();
File outFile = new File(filePath);
if ((outFile.equals("") == false)
&& (outFile.equals("null") == false)
&& ((outFile == null) == false)) {
try {
FileReader fr = new FileReader(getLogFilenamePath(0));
BufferedReader br = new BufferedReader(fr);
FileWriter saveFile = new FileWriter(outFile.toString());
int count = 0;
boolean moreLines = true;
String ln1 = "";
String ln2 = "";
String ln3 = "";
while (moreLines == true) {
ln1 = br.readLine();
ln2 = br.readLine();
ln3 = br.readLine();
if (ln1 == null) {
ln1 = "";
}
if (ln2 == null) {
ln2 = "";
}
if (ln3 == null) {
ln3 = "";
}
saveFile.write(ln1);
saveFile.write("\r\n");
saveFile.write(ln2);
saveFile.write("\r\n");
saveFile.write(ln3);
saveFile.write("\r\n");
count++;
if (ln3.equals("")) {
moreLines = false;
br.close();
saveFile.close();
JOptionPane.showMessageDialog(
null,
"Successfully exported " + count
+ " archive records to "
+ outFile.toString(), "Export",
JOptionPane.INFORMATION_MESSAGE);
}
}
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(null,
"Unable to locate Glacier.log", "Error",
JOptionPane.ERROR_MESSAGE);
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
if (e.getSource() == viewLog || e.getSource() == logButton) {
JHyperlinkLabel.OpenURI(""
+ SimpleGlacierUploader
.getLogFilenamePath(getLogFileType()).toURI());
}
if (e.getSource() == deleteArchiveMnu) {
if (checkAllFields()) {
AmazonGlacierClient newDeleteClient = new AmazonGlacierClient();
newDeleteClient = makeClient(accessString, secretString,
regionInt);
DeleteArchiveFrame daf = new DeleteArchiveFrame(
newDeleteClient, vaultString, regionInt);
daf.setVisible(true);
}
}
if (e.getSource() == inventoryRequestButton) {
if (checkAllFields()) {
AmazonGlacierClient newInventoryClient = new AmazonGlacierClient();
newInventoryClient = makeClient(accessString, secretString,
regionInt);
InventoryRequest ir = new InventoryRequest(newInventoryClient,
vaultString, regionInt);
ir.setVisible(true);
}
}
if (e.getSource() == downloadRequestButton
|| e.getSource() == downloadFileMnu) {
if (checkAllFields()) {
AmazonGlacierClient newDownloadClient = new AmazonGlacierClient();
newDownloadClient = makeClient(accessString, secretString,
regionInt);
BasicAWSCredentials credentials = new BasicAWSCredentials(
accessString, secretString);
AmazonDownloadRequest adr = new AmazonDownloadRequest(
newDownloadClient, vaultString, regionInt, credentials);
adr.setVisible(true);
}
}
if (e.getSource() == aboutMnu) {
JOptionPane.showMessageDialog(null, ABOUT_WINDOW_STRING, "About",
JOptionPane.INFORMATION_MESSAGE);
}
if (e.getSource() == clearButton) {
ddText.setText("");
uploadButton.setText("Select Files");
multiFiles = null;
}
if (e.getSource() == locationChoice) {
repopulateVaults(accessString, secretString, regionInt);
}
if (e.getSource() == selectFileButton) {
int returnVal = fc.showOpenDialog(SimpleGlacierUploader.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
if (fc.getSelectedFile().isFile()) {
/*
* Removed for v. 0.72 if (fc.getSelectedFile().length() >
* max_file_size == true) {
* JOptionPane.showMessageDialog(null,
* FILE_TOO_BIG_ERROR,"Error",JOptionPane.ERROR_MESSAGE);
* try { //ddText.setForeground(rc); ddText.append(
* "Unable to upload: " +
* fc.getSelectedFile().getCanonicalPath() + "\n" ); } //
* end try catch( java.io.IOException g ) {} } else {
*/
File[] thisFile = new File[1];
thisFile[0] = fc.getSelectedFile();
try {
ddText.append(thisFile[0].getCanonicalPath() + "\n");
} // end try
catch (java.io.IOException f) {
}
if (multiFiles != null) {
multiFiles = concatFileArray(multiFiles, thisFile);
} else {
multiFiles = thisFile;
}
// }
} else {
JOptionPane.showMessageDialog(null, NO_DIRECTORIES_ERROR,
"Error", JOptionPane.ERROR_MESSAGE);
}
} else {
}
}
if (e.getSource() == uploadButton) {
if ((checkAllFields()) && (checkForFile())) {
SaveCurrentProperties(accessString, secretString, vaultString,
locationChoice.getSelectedIndex());
SwingWorker uploadWorker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
String accessString = getAccessField();
String secretString = getSecretField();
// String vaultString = getVaultField();
String vaultName = getVaultField();
File[] uploadFileBatch = multiFiles;
// work out exactly how much we are going to upload
// so we can support a second total upload progress bar
long totalSize = 0;
long uploadedSize = 0;
for (File f : uploadFileBatch) {
totalSize += f.length();
}
int locInt = locationChoice.getSelectedIndex();
multiFiles = null;
clearFile();
UploadWindow uw = new UploadWindow();
if (uploadFileBatch.length > 0) {
ArrayList<String> uploadList = new ArrayList<String>();
for (int i = 0; i < uploadFileBatch.length; i++) {
// Save Current Settings to properties
try {
Thread.sleep(100L);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
ClientConfiguration config = new ClientConfiguration();
config.setSocketTimeout(SOCKET_TIMEOUT);
config.setMaxErrorRetry(MAX_RETRIES);
BasicAWSCredentials credentials = new BasicAWSCredentials(
accessString, secretString);
client = new AmazonGlacierClient(credentials,
config);
Endpoints ep = new Endpoints(locInt);
// String endpointUrl = ep.Endpoint(locInt);
client.setEndpoint(ep.Endpoint());
String locationUpped = ep.Location();