示例#1
0
        public virtual bool write(cape.File outfile)
        {
            if (!(outfile != null))
            {
                return(false);
            }
            if (!(data != null))
            {
                return(false);
            }
            var os = cape.PrintWriterWrapper.forWriter((cape.Writer)outfile.write());

            if (!(os != null))
            {
                return(false);
            }
            var it = data.iterate();

            while (it != null)
            {
                var kvp = it.next();
                if (!(kvp != null))
                {
                    break;
                }
                os.println(kvp.key + ": " + kvp.value);
            }
            return(true);
        }
        public bool loadFile(cape.LoggingContext ctx, cape.File file)
        {
            if (!(file != null))
            {
                ctx.logError("DynamicModule" + ": Null file");
                return(false);
            }
            if (!file.isFile())
            {
                ctx.logError("DynamicModule" + ": Not a file: `" + file.getPath() + "'");
                return(false);
            }
            ctx.logDebug("Loading dynamic module: `" + file.getPath() + "'");
            string error = null;

            ctx.logError("Loading assemblies on UWP: Not supported");
            if (assembly == null)
            {
                if (error != null)
                {
                    ctx.logDebug(error);
                }
                ctx.logError("Failed to load assembly: `" + file.getPath() + "'");
                return(false);
            }
            ctx.logDebug("Assembly successfully loaded: `" + file.getPath() + "'");
            return(true);
        }
示例#3
0
        public virtual bool writeToFile(cape.File file)
        {
            if (!(file != null))
            {
                return(false);
            }
            if (getIsDirectory())
            {
                return(file.createDirectoryRecursive());
            }
            var reader = getContentReader();

            if (!(reader != null))
            {
                return(false);
            }
            var fp = file.getParent();

            if (fp != null)
            {
                fp.createDirectoryRecursive();
            }
            var writer = file.write();

            if (!(writer != null))
            {
                if (reader is cape.Closable)
                {
                    ((cape.Closable)reader).close();
                }
                return(false);
            }
            var buf = new byte[4096 * 4];
            var v   = true;
            var n   = 0;

            while ((n = reader.read(buf)) > 0)
            {
                var nr = writer.write(buf, n);
                if (nr != n)
                {
                    v = false;
                    break;
                }
            }
            if (!v)
            {
                file.remove();
            }
            if (reader != null && reader is cape.Closable)
            {
                ((cape.Closable)reader).close();
            }
            if (writer != null && writer is cape.Closable)
            {
                ((cape.Closable)writer).close();
            }
            return(v);
        }
示例#4
0
 public cape.ProcessLauncher addToParams(cape.File file)
 {
     if (file != null)
     {
         addToParams(file.getPath());
     }
     return(this);
 }
示例#5
0
 public static object parse(cape.File file)
 {
     if (file == null)
     {
         return(null);
     }
     return(cape.JSONParser.parse(file.getContentsString("UTF-8")));
 }
示例#6
0
 public static cape.FileInfo forFile(cape.File file)
 {
     if (file == null)
     {
         return(new cape.FileInfo());
     }
     return(file.stat());
 }
示例#7
0
 public FontDescription()
 {
     file      = null;
     name      = "Sans";
     size      = cave.Length.forMicroMeters((double)2500);
     bold      = false;
     italic    = false;
     underline = false;
 }
示例#8
0
        public cape.File getFileValue(string key, cape.File defval = null)
        {
            var v = getRelativeFile(getStringValue(key, null));

            if (!(v != null))
            {
                return(defval);
            }
            return(v);
        }
示例#9
0
        public static capex.util.SimpleConfigFile forFile(cape.File file)
        {
            var v = new capex.util.SimpleConfigFile();

            if (!v.read(file))
            {
                return(null);
            }
            return(v);
        }
示例#10
0
        public static cape.DynamicMap readFileAsMap(cape.File file)
        {
            var cf = capex.util.SimpleConfigFile.forFile(file);

            if (!(cf != null))
            {
                return(null);
            }
            return(cf.getDataAsMap());
        }
示例#11
0
        public static capex.util.DynamicModule forFile(cape.LoggingContext ctx, cape.File file)
        {
            var v = new capex.util.DynamicModule();

            if (v.loadFile(ctx, file) == false)
            {
                v = null;
            }
            return(v);
        }
示例#12
0
        public cave.FontDescription forFile(cape.File file, cave.Length size = null)
        {
            var v = new cave.FontDescription();

            v.setFile(file);
            if (size != null)
            {
                v.setSize(size);
            }
            return(v);
        }
示例#13
0
 public static bool isModuleFile(cape.LoggingContext ctx, cape.File file)
 {
     if (!(file != null))
     {
         return(false);
     }
     if (file.hasExtension("dll"))
     {
         return(true);
     }
     return(false);
 }
示例#14
0
        public static cape.File forRelativePath(string path, cape.File relativeTo, bool alwaysSupportWindowsPathnames = false)
        {
            if (relativeTo == null)
            {
                return(cape.FileInstance.forPath(path));
            }
            if (object.Equals(path, null))
            {
                return((cape.File) new cape.FileInvalid());
            }
            if (cape.Environment.isAbsolutePath(path))
            {
                return(cape.FileInstance.forPath(path));
            }
            var sep = cape.Environment.getPathSeparator();

            if (sep != '/')
            {
                if (cape.String.indexOf(path, sep) < 0 && cape.String.indexOf(path, '/') >= 0)
                {
                    sep = '/';
                }
            }
            else if (alwaysSupportWindowsPathnames)
            {
                if (cape.String.indexOf(path, sep) < 0 && cape.String.indexOf(path, '\\') >= 0)
                {
                    sep = '\\';
                }
            }
            var f     = relativeTo;
            var comps = cape.String.split(path, sep);

            if (comps != null)
            {
                var n = 0;
                var m = comps.Count;
                for (n = 0; n < m; n++)
                {
                    var comp = comps[n];
                    if (comp != null)
                    {
                        if (cape.String.isEmpty(comp))
                        {
                            continue;
                        }
                        f = f.entry(comp);
                    }
                }
            }
            return(f);
        }
示例#15
0
        public virtual bool isSame(cape.File file)
        {
            if (!(file != null))
            {
                return(false);
            }
            var path = getPath();

            if (path != null && object.Equals(path, file.getPath()))
            {
                return(true);
            }
            return(false);
        }
示例#16
0
        public static string typeForFile(cape.File f)
        {
            if (!(f != null))
            {
                return("application/unknown");
            }
            var mtr = capex.util.MimeTypeRegistry.instance();
            var v   = mtr.getMimetype(f.baseName());

            if (cape.String.isEmpty(v))
            {
                return("application/unknown");
            }
            return(v);
        }
示例#17
0
        public static cape.File forDirectory(cape.File dir)
        {
            var ff = cape.TemporaryFile.forDirectory(dir, null);

            if (!(ff != null))
            {
                return(null);
            }
            ff.remove();
            ff.createDirectoryRecursive();
            if (!ff.isDirectory())
            {
                return(null);
            }
            return(ff);
        }
示例#18
0
 public override bool addFile(cape.File file, string filename)
 {
     if (!(archive != null))
     {
         return(false);
     }
     if (!(file != null))
     {
         return(false);
     }
     if (System.IO.Compression.ZipFileExtensions.CreateEntryFromFile(archive, file.getPath(), filename) == null)
     {
         return(false);
     }
     return(true);
 }
示例#19
0
        public static capex.text.XMLParser forFile(cape.File file)
        {
            if (!(file != null))
            {
                return(null);
            }
            var reader = file.read();

            if (!(reader != null))
            {
                return(null);
            }
            var v = new capex.text.XMLParser();

            v.it = (cape.CharacterIterator) new cape.CharacterIteratorForReader((cape.Reader)reader);
            return(v);
        }
示例#20
0
        /// <summary>
        /// Creates a process launcher for the given command. The command can either be a
        /// full or relative path to an executable file or, if not, a matching executable
        /// file will be searched for in the PATH environment variable (or through other
        /// applicable standard means on the given platform), and an appropriately
        /// configured ProcessLauncher object will be returned. However, if the given
        /// command is not found, this method returns null.
        /// </summary>

        public static cape.ProcessLauncher forCommand(string command, object[] @params = null)
        {
            if (cape.String.isEmpty(command))
            {
                return(null);
            }
            cape.File file = null;
            if (cape.String.indexOf(command, cape.Environment.getPathSeparator()) >= 0)
            {
                file = cape.FileInstance.forPath(command);
            }
            else
            {
                file = cape.Environment.findCommand(command);
            }
            return(cape.ProcessLauncher.forFile(file, @params));
        }
示例#21
0
        public bool read(cape.File file)
        {
            if (!(file != null))
            {
                return(false);
            }
            var buf = new cape.PrintReader((cape.Reader)file.read());

            if (!(buf != null))
            {
                return(false);
            }
            var n = 0;

            while (true)
            {
                var line = buf.readLine();
                if (!(line != null))
                {
                    break;
                }
                var va = cape.String.split(line, ':');
                cape.Iterator <string> val = cape.Vector.iterate(va);
                if (val != null)
                {
                    var front = val.next();
                    var back  = val.next();
                    if (front != null)
                    {
                        front = cape.String.strip(front);
                    }
                    if (back != null)
                    {
                        back = cape.String.strip(back);
                    }
                    if (add(front, back))
                    {
                        n++;
                    }
                }
            }
            return(true);
        }
示例#22
0
        public static capex.data.SQLiteDatabase forFile(cape.File file, bool allowCreate = true, cape.LoggingContext logger = null)
        {
            if (!(file != null))
            {
                return(null);
            }
            var v = capex.data.SQLiteDatabase.instance();

            if (!(v != null))
            {
                return(null);
            }
            if (logger != null)
            {
                v.setLogger(logger);
            }
            if (!file.isFile())
            {
                if (allowCreate == false)
                {
                    return(null);
                }
                var pp = file.getParent();
                if (pp.isDirectory() == false)
                {
                    if (pp.createDirectoryRecursive() == false)
                    {
                        cape.Log.error(v.getLogger() as cape.LoggingContext, "Failed to create directory: " + pp.getPath());
                    }
                }
                if (v.initialize(file, true) == false)
                {
                    v = null;
                }
            }
            else if (v.initialize(file, false) == false)
            {
                v = null;
            }
            return(v);
        }
示例#23
0
        public static capex.text.TextTemplate forFile(cape.File file, string markerBegin, string markerEnd, int type = 0, System.Collections.Generic.List <cape.File> includeDirs = null, cape.LoggingContext logContext = null)
        {
            if (file == null)
            {
                return(null);
            }
            var text = file.getContentsString("UTF-8");

            if (object.Equals(text, null))
            {
                return(null);
            }
            var ids = includeDirs;

            if (ids == null)
            {
                ids = new System.Collections.Generic.List <cape.File>();
                ids.Add(file.getParent());
            }
            return(capex.text.TextTemplate.forString(text, markerBegin, markerEnd, type, ids, logContext));
        }
示例#24
0
        public override bool move(cape.File dest, bool replace)
        {
            onError(null);
            if (!(dest != null))
            {
                onError("null destination");
                return(false);
            }
            if (dest.exists())
            {
                if (!replace)
                {
                    onError("target file already exists");
                    return(false);
                }
                if (dest.remove() == false)
                {
                    onError("Error when removing `" + dest.getPath() + "': " + dest.getLastErrorDescription());
                    return(false);
                }
            }
            var destf = dest as cape.FileForDotNet;

            if (!(destf != null))
            {
                return(false);
            }
            var v = true;

            try {
                System.IO.File.Move(completePath, destf.completePath);
            }
            catch (System.Exception e) {
                onError(e.ToString());
                v = false;
            }
            return(v);
        }
示例#25
0
 public static bool openFile(cape.File file)
 {
     if (cape.OS.isWindows())
     {
         var pl = cape.ProcessLauncher.forCommand("explorer", new object[] {
             file.getPath()
         });
         if (pl.executeSilent() == 0)
         {
             return(true);
         }
         return(false);
     }
     if (cape.OS.isOSX())
     {
         var pl1 = cape.ProcessLauncher.forCommand("open", new object[] {
             file.getPath()
         });
         if (pl1.executeSilent() == 0)
         {
             return(true);
         }
         return(false);
     }
     if (cape.OS.isLinux())
     {
         var pl2 = cape.ProcessLauncher.forCommand("xdg-open", new object[] {
             file.getPath()
         });
         if (pl2.executeSilent() == 0)
         {
             return(true);
         }
         return(false);
     }
     return(false);
 }
示例#26
0
        public static cape.File forDirectory(cape.File dir, string extension = null)
        {
            var tmpdir = dir;

            if (tmpdir == null)
            {
                tmpdir = cape.Environment.getTemporaryDirectory();
            }
            if (tmpdir == null || tmpdir.isDirectory() == false)
            {
                return(null);
            }
            cape.File v   = null;
            var       n   = 0;
            var       rnd = new cape.Random();

            while (n < 100)
            {
                var id = "_tmp_" + cape.String.forInteger((int)cape.SystemClock.asSeconds()) + cape.String.forInteger((int)(rnd.nextInt() % 1000000));
                if (object.Equals(extension, null) || cape.String.getLength(extension) < 1)
                {
                    id = id + extension;
                }
                v = tmpdir.entry(id);
                if (v.exists() == false)
                {
                    v.touch();
                    break;
                }
                n++;
            }
            if (v != null && v.isFile() == false)
            {
                v = null;
            }
            return(v);
        }
示例#27
0
        /// <summary>
        /// Creates a launcher for the given executable file. If the file does not exist,
        /// this method returns a null object instead.
        /// </summary>

        public static cape.ProcessLauncher forFile(cape.File file, object[] @params = null)
        {
            if (file == null || file.isFile() == false)
            {
                return(null);
            }
            var v = new cape.ProcessLauncher();

            v.setFile(file);
            if (@params != null)
            {
                var n = 0;
                var m = @params.Length;
                for (n = 0; n < m; n++)
                {
                    var param = @params[n] as string;
                    if (param != null)
                    {
                        v.addToParams(param);
                    }
                }
            }
            return(v);
        }
示例#28
0
 public abstract bool isOlderThan(cape.File bf);
示例#29
0
 public abstract bool isNewerThan(cape.File bf);
示例#30
0
 public abstract bool isIdentical(cape.File file);