Quantcast
Channel: WinBuilder
Viewing all articles
Browse latest Browse all 1056

[Solved] Coding help needed

$
0
0

In the Win7PE project on every build the old build's files are deleted in a first step.

 

This currently takes some time. And the build is waiting for completion of the delete.

On my system that takes about 45 seconds in average.

 

My idea was to start a background task which does the deletion.

 

I implemented for a windows host, and it works very well:

Average build time of a PE with standard components and internet access by M$ InternetExplorer takes about one minute!

 

I need the forum's help to code for Linux, Mac etc. My knowledge there is too small.

 

Here the current code:

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
    BackDelete "fast" deletes a directory including subdirectories
    First it renames the directory
    Second it starts an ansync process to delete the directory
    For the calling object there is the advantage that it has not to wait until deletion is finished
*/
public boolean BackDelete(File dirFile) {
    String OS = System.getProperty("os.name").toLowerCase();
    String dirPath = dirFile.getAbsolutePath();

    // to avoid troubles if the rename target exists, use an unique extention depending on time
    DateFormat formatter = new SimpleDateFormat(".HHmmss");
    String newExtention = formatter.format(new Date());

    String argRen;
    String argDel;
    if (OS.indexOf("win") >= 0) {
        String newName = dirFile.getName() + newExtention;
        argRen = "cmd /c ren \"" + dirPath + "\" \"" + newName + "\"";
        argDel = "cmd /c rmdir /S /Q \"" + dirPath + newExtention + "\"";
    } else if (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") >= 0 ) {
        // ToDo
    } else if (OS.indexOf("mac") >= 0) {
        // ToDo
    } else if (OS.indexOf("sunos") >= 0) {
        // ToDo
    } 
    Runtime.getRuntime().exec(argRen);

    // give file system some time to recognize the change
    while (dirFile.exists()) {
        Thread.sleep(100);
    }

    Runtime.getRuntime().exec(argDel);
    return true;
}

I hope that some members can replace the ToDo-s

 

Peter :cheers:


Viewing all articles
Browse latest Browse all 1056

Trending Articles