Example #1
0
        private static void PackApp(string appPath, string mainAppPath)
        {
            Logger.Log("Processing App at: " + appPath);
            var zipPath = GetTemporaryDirectory();

            try
            {
                Logger.Log("Parsing Auto Values");
                var extractor = AutoValueExtractor.Parse(Path.Combine(appPath, UnpackLogic.Paths.Code, UnpackLogic.Paths.AutoValues) + UnpackLogic.DataFileExt);

                Logger.Log("Copying app files for zip creation.");
                CopyFilesToZipFolder(appPath, zipPath, "MsApp", UnpackLogic.Paths.Code, UnpackLogic.Paths.Metadata);

                Logger.Log("Packaging Code files");
                PackScreens(appPath, zipPath, extractor);

                Logger.Log("Parsing AppInfo");
                var    sourcePath = Path.Combine(appPath, UnpackLogic.Paths.Metadata);
                string msAppZipPath;

                if (Directory.Exists(sourcePath))
                {
                    var metadataFiles   = Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories);
                    var appInfo         = AppInfo.Parse(File.ReadAllText(metadataFiles.Single(f => Path.GetExtension(f) == ".json")));
                    var destinationPath = Path.Combine(mainAppPath, UnpackLogic.Paths.MsPowerApps, "apps", appInfo.AppId);
                    MoveMetadataFilesFromExtract(appInfo, sourcePath, destinationPath, metadataFiles);
                    msAppZipPath = Path.Combine(destinationPath, Path.GetFileName(appInfo.MsAppPath));
                }
                else
                {
                    msAppZipPath = mainAppPath;
                }

                Logger.Log("Parsing Resource\\PublisherInfo");
                RestoreAutoNamedFiles(zipPath);

                Logger.Log($"Packing file {msAppZipPath}");
                MsAppHelper.CreateFromDirectory(zipPath, msAppZipPath);
            }
            finally
            {
                Directory.Delete(zipPath, true);
            }
        }
Example #2
0
        private static void PackScreens(string appPath, string zipPath, string pathCode, string pathControls)
        {
            if (!Directory.Exists(Path.Combine(appPath, pathCode)))
            {
                return;
            }

            Logger.Log("Parsing Auto Values");
            var extractor = AutoValueExtractor.Parse(Path.Combine(appPath, pathCode, UnpackLogic.Paths.AutoValues) + UnpackLogic.DataFileExt);

            foreach (var codeDirectory in Directory.GetDirectories(Path.Combine(appPath, pathCode)))
            {
                var screen = PackScreen(codeDirectory, extractor);
                var dir    = Path.Combine(zipPath, pathControls);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                File.WriteAllText(Path.Combine(dir, screen.TopParent.ControlUniqueId) + ".json", screen.Serialize(Formatting.Indented));
            }
        }