{
if(firstFile){ //If first file retrieve AES Key
if(ServerConfiguration.debug)
JOptionPane.showMessageDialog(null, "EDIT PERMISSIONS - SEL. oldAclSEL: " + oldAclSEL + "\nFileID: " + fileID );
DownloadManager downloadManager = new DownloadManager();
SessionManager.saveSession(userWhoMakeRequest, downloadManager);
downloadManager.setAcl(oldAclSEL);
downloadManager.setDownloadManager(fileID, false, "0", "0");
String IdToken = downloadManager.getID();
if(ServerConfiguration.debug)
JOptionPane.showMessageDialog(null, "EDIT PERMISSIONS - SEL. TokenID = " + IdToken);
boolean firstStep = true;
String nextToken = "";
String jsonPath = ServerConfiguration.getTempFilePath() + "/" + tempFileName + "_json.txt";
String nextPath = ServerConfiguration.getTempFilePath() + "/" + tempFileName + "_next.txt";
aesKeyPath = ServerConfiguration.getTempFilePath() + "/" + tempFileName + "_AESKey.txt";
boolean destinationACLReached;
do{
String json = downloadManager.createJson(nextToken,firstStep);
if(ServerConfiguration.debug)
JOptionPane.showMessageDialog(null, "JSON importante: " + json);
//write json.txt
FileSystemUtils.writeFile(jsonPath, json);
//FileUtility.writeFile(jsonPath, json);
if(ServerConfiguration.debug)
JOptionPane.showMessageDialog(null, "controlla se esiste il file json - firstStep = " + firstStep);
if(firstStep == true)
{
//run wpes1
String command[] = {
ServerConfiguration.getEXECUTABLES_PATH() + "/wpes1_linux",
"dec1",
jsonPath,
PIN,
aesKeyPath,
IdToken,
nextPath
};
RunnerExecutables.execute(command);
firstStep = false;
}
else
{
//run wpes1
String command[] = {
ServerConfiguration.getEXECUTABLES_PATH() + "/wpes1_linux",
"decn",
jsonPath,
aesKeyPath,
aesKeyPath,
IdToken,
nextPath
};
RunnerExecutables.execute(command);
}
//read next.txt
if(ServerConfiguration.debug)
JOptionPane.showMessageDialog(null, "Ora legge nextPath");
nextToken = FileSystemUtils.readFile(nextPath);
//nextToken = FileUtility.readFile(nextPath);
destinationACLReached = downloadManager.finished(nextToken);
//remove Json.txt file from temp because the file is used
//only by the executable and it will rewrite
FileUtility.deleteTempFile(jsonPath);