Exemple #1
0
        public void Initialize(ZipData data)
        {
            Data = data;

            Opacity = 0;

            AddTabs(data);

            Highlight(0);
        }
        /*
         * The default visible view is Expand button,
         * if there are MaxCount or fewer tabs, show all of them via FileTabs
         *
         */
        public void Initialize(ZipData data)
        {
            if (data.StyleFileNames.Count <= MaxCount)
            {
                Tabs.IsVisible = true;
                Tabs.Update(data);
                ExpandButton.IsVisible = false;
            }
            else
            {
                ExpandButton.Update(data.StyleFileNames[0]);
            }

            LayoutSubviews();
        }
Exemple #3
0
        void AddTabs(ZipData data)
        {
            items = new List <FileTab>();

            Children.Clear();
            items.Clear();

            List <string> names = data.StyleFileNames;
            int           index = 0;

            foreach (string name in names)
            {
                FileTab tab = new FileTab(name, index);
                AddSubview(tab);
                items.Add(tab);

                tab.Tapped += OnTap;

                index++;
            }

            LayoutSubviews();
        }
        public void Update(ZipData data)
        {
            Children.Clear();
            items.Clear();


            double x = 0;
            double y = 0;
            double w = TabWidth;
            double h = Height;

            List <string> names = data.StyleFileNames;
            int           index = 0;

            foreach (string name in names)
            {
                FileTab tab = new FileTab(name, index);
                AddSubview(tab, x, y, w, h);
                items.Add(tab);

                tab.Tapped += OnTap;

                if ((int)Math.Ceiling(x + w) == (int)Width)
                {
                    x  = 0;
                    y += h;
                }
                else
                {
                    x += w;
                }

                index++;
            }

            Highlight(0);
        }
 public void Initialize(ZipData items)
 {
     this.items = items;
     Update(0);
 }
 public void Initialize(ZipData data)
 {
     Data = data;
     LayoutSubviews();
 }
		public static ZipData GetZipData(string folder, string filename)
		{
			ZipData data = new ZipData();

			string fullPath = Path.Combine(folder, filename);
			string newFolder = filename.Replace(ZipExtension, "");
			string decompressedPath = Path.Combine(folder, newFolder);

			List<string> paths = Decompress(fullPath, decompressedPath);

			data.Filename = filename;
			data.DecompressedPath = decompressedPath;
			data.AllFilePaths = paths;

			/*
			 * The Zip itself can contain extra .mss files and presents them in the wrong order.
			 * Read the necessary .mss files and their order from project.json
			 */
			foreach (string path in paths)
			{
                string[] split = path.Split('/');
                if (split[split.Length - 1].Equals(ProjectFile))
				{
#if __UWP__
                    using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read))
                    {
                        using (var streamReader = new StreamReader(stream))
#else
					using (var streamReader = new StreamReader(path))
#endif
					{
						if (path.Contains("__MACOSX"))
						{
							/* 
							 * OSX Creates a __MAXOSX folder every time you zip an archive:
							 * 
                             * The Mac OS X has a "forked" filesystem called HFS+ - in particular, 
                             * many files have a "resource fork" in addition to the "data fork" 
                             * (the more common place where data is stored).  
                             * The __MACOSX folders in a zip file allow the zipped file to 
                             * retain the additional forks like the resource fork.
							 * 
							 * However, in our case, we must ignore that folder since it contains metadata
							 * that cannot be parsed into json and causes the application to crash
							 * 
							 * Ideally, if zipping on osx, you should do it without the rather pointless metadata,
							 * as it just increases the size of the file anyway.
							 * You should use a third-party service like Keka (http://www.kekaosx.com/en/) tha
							 * 
							 */
							continue;
						}

                        if (path.Contains(".DS_Store"))
                        {
                            /*
                             * DS_Store is a file that stores custom attributes of its containing folder, 
                             * such as the position of icons or the choice of a background image.
                             */
                            continue;
						}

						string content = streamReader.ReadToEnd();
						Variant json = Variant.FromString(content);
						Variant styles = json.GetObjectElement("styles");

						for (int i = 0; i < styles.ArraySize; i++)
						{
							string styleFileName = styles.GetArrayElement(i).String;

							foreach (string mssPath in paths)
							{
								if (mssPath.Contains("__MACOSX"))
								{
									/* cf. explanation above */
									continue;
								}

								if (mssPath.Contains(styleFileName))
								{
#if __UWP__
                                        using (var stream2 = new FileStream(mssPath, FileMode.Open, FileAccess.Read))
                                        {
                                            using (var mssReader = new StreamReader(stream2))
#else
									using (var mssReader = new StreamReader(mssPath))
#endif
									{
										string styleContent = mssReader.ReadToEnd();
										data.DecompressedFiles.Add(styleContent);
									}

									data.StyleFileNames.Add(styleFileName);
									data.StyleFilePaths.Add(mssPath);
#if __UWP__
                                        }
#endif
								}
							}
						}

                        data.StyleFileNames.Add(ProjectFile);
                        data.StyleFilePaths.Add(path);
                        data.DecompressedFiles.Add(content);
					}
#if __UWP__
                    }
#endif
				}
			}

			return data;
		}
Exemple #8
0
        public async Task <string> Update(string owner, string name, string path, string branch, ZipData data, string message)
        {
            /*
             * TODO Perhaps it would be better to pass the List<GithubFiles> when pushing MainController,
             * current we're downloading the content again
             */

            var contents = await GetRepositoryContent(owner, name, branch, path);

            var files = contents.ToGithubFiles();

            /*
             * TODO We assume that these files exist, so they're updated, not created
             * Additionally, we assume the branch exists. No new branch creation is possible
             *
             * Branch creation possible via https://github.com/octokit/octokit.rb/issues/571,
             * something like:
             * client.Git.Reference.Create(owner, name, new NewReference("heads/<new-branch-name>", "<sha1-of-something>"));
             */

            try
            {
                foreach (GithubFile file in files)
                {
                    for (int i = 0; i < data.StyleFileNames.Count; i++)
                    {
                        string filename = data.StyleFileNames[i];
                        if (file.Name.Equals(filename) && data.ChangeList.Contains(filename))
                        {
                            string content = data.DecompressedFiles[i];

                            // Full path is required; add the filename
                            path += "/" + filename;

                            var request   = new UpdateFileRequest(message + " (" + path + ")", content, file.Sha, branch);
                            var changeSet = await client.Repository.Content.UpdateFile(owner, name, path, request);

                            return(null);
                        }
                    }
                }

                return("You haven't made any changes. What exactly should I commit?");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();

            ContentView.ShowLoading();

            Task.Run(delegate
            {
                data = Parser.GetZipData(folder, filename);

                Device.BeginInvokeOnMainThread(delegate
                {
                    ContentView.Initialize(data);
                });

                byte[] zipBytes = FileUtils.PathToByteData(data.DecompressedPath + Parser.ZipExtension);

                Device.BeginInvokeOnMainThread(delegate
                {
                    ContentView.UpdateMap(zipBytes, delegate
                    {
                        ContentView.HideLoading();
                    });
                });
            });

            ContentView.NavigationBar.Back.Click += OnBackButtonPressed;

            ContentView.FileTabs.OnTabTap     += OnTabTapped;
            ContentView.Toolbar.Tabs.OnTabTap += OnTabTapped;

            ContentView.Toolbar.ExpandButton.Click += OnFileTabExpand;
            ContentView.Toolbar.UploadButton.Click += OnUploadButtonClicked;
            ContentView.Toolbar.SaveButton.Click   += OnSaveButtonClicked;
            ContentView.Toolbar.EmailButton.Click  += OnEmailButtonClicked;

            ContentView.MapView.RefreshButton.Click += OnRefresh;

            ContentView.GithubUpload.Content.Commit.Clicked += OnGithubCommitButtonClicked;

            //ContentView.MapView.SourceLabel.Done += OnSourceChanged;

            ContentView.Editor.Popup.Box.Button.Click += OnWarningPopupButtonClicked;

            ContentView.NavigationBar.Edit.Click += OnTitleEditClicked;

            ContentView.NavigationBar.EditingEnded += OnTitleEditComplete;

#if __ANDROID__
            DriveClientDroid.Instance.UploadComplete += OnUploadComplete;
#elif __IOS__
            DriveClientiOS.Instance.UploadComplete += OnUploadComplete;
#elif __UWP__
            ContentView.Zoom.In.Click  += ZoomIn;
            ContentView.Zoom.Out.Click += ZoomOut;
#endif

            timer.Initialize(ContentView);

            ContentView.Editor.Field.InitializeTimer();

            ContentView.NavigationBar.AttachHandlers();
        }