Ejemplo n.º 1
0
        private bool applyFileChange(GhostFile file, String tmpPath)
        {
            Logger.log(Logger.TYPE.DEBUG, "Apply file change " + file.getName() + " path: " + tmpPath);
            bool   success = true;
            String tmpFile = Path.Combine(tmpPath, file.getName());
            String newPath = Path.Combine(getRootDir(), ((file is Archive) ?
                                                         ((Archive)file).getExtractTo() : file.getDestination()));

            if (verifyFile(tmpFile))
            {
                if (ensureDirectory(newPath))
                {
                    if (file is Archive)
                    {
                        try {
                            Archive archive = (Archive)file;
                            if (archive.getCleanDirs())
                            {
                                // TODO: Clean root directory
                            }

                            ArchiveHandler.extractZip(tmpFile, newPath, archive.getCleanDirs());

                            Logger.log(Logger.TYPE.DEBUG, "Extracted archive " + tmpFile + " to " + newPath);
                        }
                        catch (Exception ex) {
                            Logger.log(Logger.TYPE.ERROR, "Unable to patch new file to required"
                                       + " path. " + file.getName() + " " + ex.Message + ex.StackTrace);

                            success = false;
                        }
                    }
                    else
                    {
                        try {
                            File.Copy(tmpFile, Path.Combine(newPath, file.getName()), true);

                            Logger.log(Logger.TYPE.DEBUG, "Copied " + tmpFile + " to " + newPath);
                        }
                        catch (Exception ex) {
                            Logger.log(Logger.TYPE.ERROR, "Unable to patch new file to required"
                                       + " path. " + file.getName() + " " + ex.Message + ex.StackTrace);

                            success = false;
                        }
                    }
                }
            }
            return(success);
        }
Ejemplo n.º 2
0
        public void getFonts(FontAsyncCallback callback)
        {
            Logger.log(Logger.TYPE.DEBUG, "Getting fonts...");

            var root = from item in serverXMLCache.get().Descendants("Server")
                       select new {
                fonts = item.Descendants("Font")
            };

            List <FontPackage> packages = new List <FontPackage>();

            foreach (var data in root)
            {
                foreach (var f in data.fonts)
                {
                    packages.Add(new FontPackage(f));
                }
            }

            List <String> installedFonts = new List <String>();

            String fontCachePath = client.getFontCacheDir();
            String tmpFontPath   = Path.Combine(fontCachePath, "tmpfonts");

            if (!Directory.Exists(fontCachePath))
            {
                Directory.CreateDirectory(fontCachePath);
                Directory.CreateDirectory(tmpFontPath);
            }
            else
            {
                if (!Directory.Exists(tmpFontPath))
                {
                    Directory.CreateDirectory(tmpFontPath);
                }
                // Preload already existing fonts
                installedFonts = installPrivateFonts(fontCachePath);
            }

            if (packages.Count > 0)
            {
                // Download font packages
                foreach (FontPackage package in packages)
                {
                    if (!FontHandler.doesFontExist(package.getName(), true, true))
                    {
                        if (package.canDownload())
                        {
                            Uri packageUrl = new Uri(getUrl() + "/" + package.getPackage());
                            dlHandler.enqueueFile(packageUrl, tmpFontPath,
                                                  package.getArchiveName(), (Boolean cancelled) => {
                                if (!cancelled)
                                {
                                    ArchiveHandler.extractZip(Path.Combine(tmpFontPath,
                                                                           package.getArchiveName()), tmpFontPath, false);
                                }
                            });
                        }
                    }
                    else
                    {
                        package.setInstalled(true);
                    }
                }

                dlHandler.setQueueFileCallback(new QueueCallback(() => {
                    installedFonts.AddRange(installPrivateFonts(tmpFontPath));

                    // Finished installing new fonts, now cache them
                    cacheFonts(tmpFontPath);

                    // Apply new fonts to the packages
                    foreach (FontPackage package in packages)
                    {
                        if (FontHandler.doesPrivateFontExist(package.getName(), true))
                        {
                            package.setInstalled(true); // Ensure package is now installed

                            foreach (KeyValuePair <String, FontApply> pair in package.getApplyMap())
                            {
                                FontApply fontApply = pair.Value;
                                fontApply.usePrivateFont(package.getName());
                            }
                        }
                    }

                    callback.onSuccess(packages);
                }));

                dlHandler.startFileQueue();
            }
            else
            {
                callback.onSuccess(packages);
            }
        }