Esempio n. 1
0
        private static void PackZip(Args.Args options)
        {
            var zipPath = GetTemporaryDirectory();

            try
            {
                CopyFilesToZipFolder(options.UnpackPath, zipPath, "non app source files", UnpackLogic.Paths.Apps);
                foreach (var appPath in Directory.GetDirectories(Path.Combine(options.UnpackPath, UnpackLogic.Paths.Apps)))
                {
                    PackApp(appPath, zipPath);
                }

                Logger.Log("Creating zip file " + options.PackageZip);
                if (File.Exists(options.PackageZip))
                {
                    File.Delete(options.PackageZip);
                }

                ZipFile.CreateFromDirectory(zipPath, options.PackageZip);
            }
            finally
            {
                Directory.Delete(zipPath, true);
            }
        }
Esempio n. 2
0
 private static void ExtractCanvasApp(string appDirectory, Args.Args options)
 {
     var codeDirectory      = Path.Combine(appDirectory, Paths.Code);
     var controlsDir        = Path.Combine(appDirectory, Paths.Controls);
     var autoValueExtractor = new AutoValueExtractor();
     var header             = File.ReadAllText(Path.Combine(appDirectory, Paths.Header));
     var indexOfDocVersion  = header.IndexOf(DocVersionStartText, StringComparison.InvariantCultureIgnoreCase) + DocVersionStartText.Length;
     var version            = new Version(header[indexOfDocVersion
Esempio n. 3
0
 private static void Pack(Args.Args options)
 {
     if (!Directory.Exists(options.UnpackPath))
     {
         Logger.Error($"Directory at: \"{options.UnpackPath}\" does not exist!");
         return;
     }
     PackLogic.Pack(options);
 }
Esempio n. 4
0
        private static void Unpack(Args.Args options)
        {
            if (string.Equals(options.PackageZip, "latest", StringComparison.OrdinalIgnoreCase))
            {
                options.PackageZip = GetLatestZipFromDownloads().FullName;
            }

            if (!File.Exists(options.PackageZip))
            {
                Logger.Error($"File at: \"{options.PackageZip}\" does not exist!");
                return;
            }

            UnpackLogic.Unpack(options.PackageZip, options.UnpackPath, options);
        }
Esempio n. 5
0
 public static void Pack(Args.Args options)
 {
     if (File.Exists(Path.Combine(options.UnpackPath, UnpackLogic.Paths.ManifestFileName)))
     {
         PackZip(options);
     }
     else if (File.Exists(Path.Combine(options.UnpackPath, UnpackLogic.Paths.Header)))
     {
         PackApp(options.UnpackPath, options.PackageZip);
     }
     else
     {
         throw new Exception("There is no manifest.json or Header.json found in the extract folder");
     }
 }
        private static void ExtractCanvasApp(string appDirectory, Args.Args options)
        {
            var codeDirectory          = Path.Combine(appDirectory, Paths.Code);
            var componentCodeDirectory = Path.Combine(appDirectory, Paths.ComponentCode);
            var controlsDir            = Path.Combine(appDirectory, Paths.Controls);
            var componentsDir          = Path.Combine(appDirectory, Paths.Components);
            var header = File.ReadAllText(Path.Combine(appDirectory, Paths.Header));


            // It's important to use proper JSON deserialization since the whitepsace is unpredictable.
            var headerObj = JsonConvert.DeserializeObject <Header>(header);
            var version   = new Version(headerObj.DocVersion);

            ExtraCodeful(controlsDir, codeDirectory, version, options);
            ExtraCodeful(componentsDir, componentCodeDirectory, version, options);

            RenameAutoNamedFiles(appDirectory);
        }
Esempio n. 7
0
        private static void ExtractApps(string outputDirectory, Args.Args options)
        {
            if (!Directory.Exists(Path.Combine(outputDirectory, Paths.MsPowerApps)))
            {
                Logger.Error($"Invalid zip file.  Missing root folder \"{Paths.MsPowerApps}\"");
                return;
            }

            var appsPath = Path.Combine(outputDirectory, Paths.MsPowerApps, Paths.PackageApps);

            foreach (var appSourcePath in Directory.GetDirectories(appsPath))
            {
                var appInfo       = AppInfo.Parse(File.ReadAllText(Path.Join(appSourcePath, Path.GetFileName(appSourcePath)) + ".json"));
                var appOutputPath = Path.Combine(outputDirectory, Paths.Apps, string.IsNullOrWhiteSpace(options.NameOfApplication) ? appInfo.DisplayName: options.NameOfApplication);
                Logger.Log($"Extracting App {appInfo.DisplayName} - {appInfo.Description}");
                var msAppFilePath = Path.Combine(appsPath, appInfo.MsAppPath);
                Unpack(msAppFilePath, appOutputPath, options);
                MoveMetadataFiles(appInfo, appOutputPath, msAppFilePath);
            }
        }
Esempio n. 8
0
        public static void Unpack(string file, string outputDirectory, Args.Args options)
        {
            if (options.Clobber && Directory.Exists(outputDirectory))
            {
                Logger.Log("Deleting files in " + outputDirectory);
                Directory.Delete(outputDirectory, true);
            }

            Logger.Log("Extracting files from " + file + " to " + outputDirectory);
            if (Path.GetExtension(file).ToLower() == ".zip")
            {
                ZipFile.ExtractToDirectory(file, outputDirectory, true);
                ExtractApps(outputDirectory, options);
            }
            else
            {
                MsAppHelper.ExtractToDirectory(file, outputDirectory, true);
                if (!options.OnlyExtract)
                {
                    ExtractCanvasApp(outputDirectory, options);
                }
            }
        }
 private static string RenameControls(string app, Args.Args options)
 {
     Logger.Log($"Renaming Controls from \"{options.RenameCopiedControlOldPostfix}\" to \"{options.RenameCopiedControlNewPostfix}\".");
     return(app.Replace(options.RenameCopiedControlOldPostfix, options.RenameCopiedControlNewPostfix));
 }
Esempio n. 10
0
        private static void ExtraCodeful(string controlsDir, string codeDirectory, Version version, Args.Args options)
        {
            if (!Directory.Exists(controlsDir))
            {
                return;
            }
            var autoValueExtractor = new AutoValueExtractor();

            foreach (var file in Directory.GetFiles(controlsDir))
            {
                Logger.Log("Extracting file " + file);
                var json = File.ReadAllText(file);
                if (!string.IsNullOrWhiteSpace(options.RenameCopiedControlOldPostfix))
                {
                    json = RenameControls(json, options);
                }
                var screen = JsonConvert.DeserializeObject <CanvasAppScreen>(json);
                VerifySerialization(screen, json, file, version);
                var fileDirectory = Path.Combine(codeDirectory, screen.TopParent.Name);
                ParseControl(screen, screen.TopParent, fileDirectory, autoValueExtractor);
            }
            File.WriteAllText(Path.Combine(codeDirectory, Paths.AutoValues) + DataFileExt, autoValueExtractor.Serialize());
            Directory.Delete(controlsDir, true);
        }