Search in sources :

Example 6 with ZipReader

use of com.laytonsmith.PureUtilities.ZipReader in project CommandHelper by EngineHub.

the class SiteDeploy method deployLearningTrail.

/**
 * Pages deployed: All files from /docs/*
 */
private void deployLearningTrail() {
    generateQueue.submit(new Runnable() {

        @Override
        public void run() {
            try {
                File root = new File(SiteDeploy.class.getResource("/docs").toExternalForm());
                ZipReader zReader = new ZipReader(root);
                for (File r : zReader.listFiles()) {
                    String filename = r.getAbsolutePath().replaceFirst(Pattern.quote(zReader.getFile().getAbsolutePath()), "");
                    writePageFromResource(r.getName(), "/docs" + filename, r.getName() + ".html", Arrays.asList(new String[] { r.getName().replace("_", " ") }), "Learning trail page for " + r.getName().replace("_", " "));
                }
            } catch (IOException ex) {
                Logger.getLogger(SiteDeploy.class.getName()).log(Level.SEVERE, null, ex);
            }
            currentGenerateTask.addAndGet(1);
        }
    });
    totalGenerateTasks.addAndGet(1);
}
Also used : ZipReader(com.laytonsmith.PureUtilities.ZipReader) IOException(java.io.IOException) File(java.io.File)

Example 7 with ZipReader

use of com.laytonsmith.PureUtilities.ZipReader in project CommandHelper by EngineHub.

the class ExampleLocalPackageInstaller method install.

private static void install(String pkg) throws IOException {
    URL url = ExampleLocalPackageInstaller.class.getResource("/local_packages/" + pkg);
    if (url == null) {
        StreamUtils.GetSystemOut().println("\"" + pkg + "\" is not a valid package name.");
        System.exit(1);
    }
    ZipReader reader = new ZipReader(url);
    File localPackages = new File(jarFolder, "CommandHelper/LocalPackages/" + pkg);
    if (localPackages.exists() && localPackages.list().length != 0) {
        StreamUtils.GetSystemOut().println("The LocalPackage " + pkg + " already exists on your system, and is not empty. Are you sure you wish to possibly overwrite files? (Y/N)");
        StreamUtils.GetSystemOut().print(">");
        String response = new Scanner(System.in).nextLine();
        if (!"Y".equalsIgnoreCase(response)) {
            System.exit(0);
        }
    }
    reader.recursiveCopy(localPackages, true);
    StreamUtils.GetSystemOut().println("Local package installed at " + localPackages);
}
Also used : Scanner(java.util.Scanner) ZipReader(com.laytonsmith.PureUtilities.ZipReader) File(java.io.File) URL(java.net.URL)

Example 8 with ZipReader

use of com.laytonsmith.PureUtilities.ZipReader in project CommandHelper by EngineHub.

the class Main method loadSelfVersion.

@SuppressWarnings({ "ThrowableInstanceNotThrown", "ThrowableInstanceNeverThrown" })
public static SimpleVersion loadSelfVersion() throws Exception {
    File file = new File(new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI()), "plugin.yml");
    ZipReader reader = new ZipReader(file);
    if (!reader.exists()) {
        throw new FileNotFoundException(String.format("%s does not exist", file.getPath()));
    }
    try {
        String contents = reader.getFileContents();
        Yaml yaml = new Yaml();
        Map<String, Object> map = (Map<String, Object>) yaml.load(contents);
        return new SimpleVersion((String) map.get("version"));
    } catch (RuntimeException | IOException ex) {
        throw new Exception(ex);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ZipReader(com.laytonsmith.PureUtilities.ZipReader) CString(com.laytonsmith.core.constructs.CString) IOException(java.io.IOException) Yaml(org.yaml.snakeyaml.Yaml) ConfigCompileException(com.laytonsmith.core.exceptions.ConfigCompileException) HeadlessException(java.awt.HeadlessException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ConfigRuntimeException(com.laytonsmith.core.exceptions.ConfigRuntimeException) ConfigCompileGroupException(com.laytonsmith.core.exceptions.ConfigCompileGroupException) ConfigRuntimeException(com.laytonsmith.core.exceptions.ConfigRuntimeException) SimpleVersion(com.laytonsmith.PureUtilities.SimpleVersion) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ZipReader (com.laytonsmith.PureUtilities.ZipReader)8 File (java.io.File)7 IOException (java.io.IOException)5 ConfigCompileException (com.laytonsmith.core.exceptions.ConfigCompileException)2 ConfigCompileGroupException (com.laytonsmith.core.exceptions.ConfigCompileGroupException)2 URISyntaxException (java.net.URISyntaxException)2 LinkedList (java.util.LinkedList)2 SimpleVersion (com.laytonsmith.PureUtilities.SimpleVersion)1 ParseTree (com.laytonsmith.core.ParseTree)1 CString (com.laytonsmith.core.constructs.CString)1 CREIOException (com.laytonsmith.core.exceptions.CRE.CREIOException)1 CREIncludeException (com.laytonsmith.core.exceptions.CRE.CREIncludeException)1 CRESecurityException (com.laytonsmith.core.exceptions.CRE.CRESecurityException)1 ConfigRuntimeException (com.laytonsmith.core.exceptions.ConfigRuntimeException)1 GenerateException (com.laytonsmith.tools.docgen.DocGenTemplates.Generator.GenerateException)1 HeadlessException (java.awt.HeadlessException)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1