public MainController(string folder, string filename)
        {
            NavigationPage.SetHasNavigationBar(this, false);

            this.folder   = folder;
            this.filename = filename;

            ContentView = new MainView(IsTemplateFolder);
            Content     = ContentView;

            ContentView.NavigationBar.IsTitleEditVisible = true;
            ContentView.NavigationBar.Title.Text         = filename.Replace(Parser.ZipExtension, "").ToUpper();

            string[] split       = folder.Split('/');
            string   styleFolder = split[split.Length - 1];
            var      localPath   = Path.Combine(styleFolder, filename.Replace(Parser.ZipExtension, ""));

            GithubData = LocalStorage.Instance.GetRepositoryData(localPath);
            ContentView.Toolbar.CanUploadToGithub = GithubData.CanUploadToGithub;

            if (!LocalStorage.Instance.WarningPopupShown)
            {
                ContentView.DisableEditor();
            }
        }
Exemplo n.º 2
0
 public bool Insert(RepositoryData item)
 {
     try
     {
         db.Insert(item);
         return(true);
     } catch
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 public void Update(RepositoryData item)
 {
     db.Update(item);
 }
Exemplo n.º 4
0
        async void OnSelectClick(object sender, EventArgs e)
        {
            if (ContentView.FileList.GithubFiles == null)
            {
                return;
            }

            Device.BeginInvokeOnMainThread(delegate
            {
                ContentView.FileList.Hide();
                ContentView.ShowLoading();
            });

            List <GithubFile>           folder = ContentView.FileList.GithubFiles;
            List <DownloadedGithubFile> files  = await HubClient.Instance.DownloadFolder(GithubOwner, GithubRepo, CurrentBranch, folder);

            Toast.Show("Saving...", ContentView);

            /*
             * This is where we update pathing -> Shouldn't use repository folder hierarcy
             * We get the root of the style folder, and use that as the root folder for our folder hierarcy
             *
             * We can safely assume the root folder of the style, not the repository,
             * contains a config file (currently only supports project.json)
             * and therefore can remove any other folder hierarchy
             *
             * TODO What if it always isn't like that? && support other types of config files
             *
             */

            DownloadedGithubFile projectFile = files.Find(file => file.IsProjectFile);

            string folderPath = projectFile.FolderPath;

            string[] split = folderPath.Split('/');

            string rootFolder     = split[split.Length - 1];
            int    length         = folderPath.IndexOf(rootFolder, StringComparison.Ordinal);
            string repoRootFolder = folderPath.Substring(0, length);

            foreach (DownloadedGithubFile file in files)
            {
                file.Path = file.Path.Replace(repoRootFolder, "");
                FileUtils.SaveFileToFolder(file.Stream, file.Path, file.Name);
            }

            string zipname = rootFolder + Parser.ZipExtension;
            string source  = Path.Combine(Parser.ApplicationFolder, rootFolder);

            Toast.Show("Comperssing...", ContentView);

            string destination = Parser.Compress(source, zipname, MyStyleFolder);

            // Destination contains filename, just remove it
            destination = destination.Replace(zipname, "");

            Toast.Show("Done!", ContentView);

            Device.BeginInvokeOnMainThread(delegate
            {
                ContentView.HideLoading();
            });

            RepositoryData item = new RepositoryData();

            item.GithubId = GithubId;

            item.StyleName = rootFolder;

            item.Owner          = GithubOwner;
            item.Name           = GithubRepo;
            item.RepositoryPath = GithubPath;

            item.Branch            = CurrentBranch;
            item.LocalPath         = Path.Combine(MyStyleFolder, rootFolder);
            item.CanUploadToGithub = true;

            item.ConstructPrimaryKey();

            bool inserted = LocalStorage.Instance.Insert(item);

            // TODO Theoretically should check this earlier to and then prompt
            // the user whether they wish to overwrite an existing style
            if (!inserted)
            {
                LocalStorage.Instance.Update(item);
            }

            ShowMyStyles();
        }