private Document CreateTempFile()
 {
     Directory root = new Directory(PathBase.Root);
     string path = FileUtils.GetNumberedDocumentPath("Temp", root.Path.PathString);
     var doc = new Document(new PathStr(path)) { IsTemp = true };
     FileUtils.CreateDocument(doc.Path.Parent.PathString, doc.DisplayName);
     return doc;
 }
 private void Dir_Tap(object sender, System.Windows.Input.GestureEventArgs e)
 {
     // Create a temporary directory that will be renamed in the new window
     string tempPath = FileUtils.GetNumberedDirectoryPath("Untitled", _currentDirectory.Path.PathString);
     Directory newDirectory = new Directory(new PathStr(tempPath)) { IsTemp = true };
     FileUtils.CreateDirectory(newDirectory.Path.Parent.PathString, newDirectory.DisplayName);
     newDirectory.NavToRename(NavigationService, this);
 }
Exemple #3
0
        private void Dir_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                // Create a temporary directory that will be renamed in the new window
                string tempName = "." + Utils.GetUniqueName(_currentDirectory, isf);
                Directory newDirectory = new Directory(_currentDirectory, tempName) { IsTemp = true };
                isf.CreateDirectory(newDirectory.Path.PathString);

                newDirectory.NavToRename(NavigationService);
            }
        }
Exemple #4
0
        public MoveListItem(Directory d)
        {
            DirectoryItem = d;

            // Set up appearance
            this.Orientation = Orientation.Vertical;
            this.Margin = new Thickness(12 + 15 * DirectoryItem.Path.Depth, 0, 0, 15);

            TextBlock name = new TextBlock();
            TextBlock path = new TextBlock();

            this.Children.Add(name);
            this.Children.Add(path);

            name.Text = DirectoryItem.Name;
            name.FontSize = 50;
            name.FontFamily = new FontFamily("Segoe WP SemiLight");
            name.Margin = new Thickness(0, 0, 0, -5);

            path.Text = DirectoryItem.Path.PathString;
            path.Foreground = (Brush)Application.Current.Resources["PhoneSubtleBrush"];
        }
Exemple #5
0
        private bool IsInIgnoreList(Directory dest, IActionable itemToMove)
        {
            bool b = false;
            foreach (IActionable a in _actionables)
                b = b || a.Path.Equals(dest.Path);

            return b ||
                   dest.Path.PathString.Equals("Shared") ||
                   dest.Path.IsInTrash;
        }
Exemple #6
0
 private StackPanel createNewDirItem(Directory d)
 {
     MoveListItem i = new MoveListItem(d);
     return i;
 }
Exemple #7
0
 // Returns a name which is unique in the current IsolatedStorage scope.
 // CreateDirectory(..) and CreateFile(.. + ".txt") are guaranteed to
 // create new items successfully.
 public static string GetUniqueName(Directory parent, IsolatedStorageFile isf)
 {
     string name = string.Empty;
     do
     {
         name = Guid.NewGuid().ToString();
     } while (isf.FileExists(parent.Path.NavigateIn(name).PathString + ".txt") ||
              isf.DirectoryExists(parent.Path.NavigateIn(name).PathString));
     return name;
 }
Exemple #8
0
        private void Navigate(Directory newDirectory, Storyboard outAnimation, Storyboard inAnimation)
        {
            outAnimation.Begin();

            _curr = newDirectory;
            Action BeginInAnimation = () =>
            {
                inAnimation.Begin();
            };
            Action WorkToDo = () =>
            {
                UpdateItems(BeginInAnimation);
            };
            outAnimation.Completed += new EventHandler((object sender, EventArgs e) =>
            {
                UpdateView(BeginInAnimation);
            });
            Action<object, RunWorkerCompletedEventArgs> RunWorkerCompletedEvent = (object sender, RunWorkerCompletedEventArgs e) =>
            {
                if (outAnimation.GetCurrentState() != ClockState.Active)
                {
                    UpdateView(BeginInAnimation);
                    outAnimation.Stop();
                }
            };

            CreateNewBackgroundWorker(WorkToDo, RunWorkerCompletedEvent)
                .RunWorkerAsync();
        }
Exemple #9
0
        // takes the parent of the new location
        public IActionable Move(Directory newLocation)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                Directory newLoc = new Directory(newLocation.Path.NavigateIn(Name));
                if (isf.DirectoryExists(newLoc.Path.PathString))
                    throw new ActionableException(this);

                isf.MoveDirectory(Path.PathString, newLoc.Path.PathString);
                return newLoc;
            }
        }
Exemple #10
0
 private void GetArgs()
 {
     IList<object> args = Utils.GetArguments();
     _currentDirectory = (Directory)args[0];
 }
 private MoveListItem createNewDirItem(Directory d)
 {
     return new MoveListItem(d);
 }
 private void TryMoveItem(IActionable a, Directory newParent)
 {
     var newLocation = Utils.CreateActionableFromPath(new PathStr(newParent.Path.NavigateIn(a.Name)));
     if (newLocation.Exists())
     {
         var type = a.GetType().Name.ToLower();
         MessageBoxResult r = MessageBox.Show(string.Format("There is already an {0} with the same name at the specified destination. Tap OK to overwrite the existing {0}, or Cancel to skip this item.", type), a.DisplayName, MessageBoxButton.OKCancel);
         if (r != MessageBoxResult.OK)
             return;
         newLocation.Delete(true);
     }
     try
     {
         a.Move(newParent);
     }
     catch (Exception ex)
     {
         return;
     }
 }
 private bool IsParent(Directory d)
 {
     var parentPath = d.Path.PathString;
     foreach (var item in _actionables)
     {
         if (item.Path.Parent.PathString.Equals(d.Path.PathString))
             return true;
     }
     return false;
 }
Exemple #14
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            var rootName = SettingUtils.GetSetting<string>(Setting.RootDirectoryName);
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!isf.DirectoryExists(rootName))
                    isf.CreateDirectory(rootName);
                if (!isf.DirectoryExists("trash.dir"))
                    isf.CreateDirectory("trash.dir");
                if (isf.DirectoryExists("root") && !IsolatedStorageSettings.ApplicationSettings.Contains("HasMovedRoot"))
                {
                    IActionable a = new Models.Directory(new PathStr("root"));

                    //var newName = "lost_files_" + new Random().Next();
                    var newName = "lost_files_";
                    var newLoc = new Models.Directory(new PathStr(PathBase.Root).NavigateIn(newName, ItemType.Directory));
                    if (!isf.DirectoryExists(newName) && !newLoc.Exists())
                    {
                        a = a.Rename(newName);
                        a = a.Move(new Models.Directory(PathBase.Root));

                        //var apologyName = "apology_" + new Random().Next();
                        var apologyName = "apology_";
                        var apologyFile = new Models.Document(new PathStr(PathBase.Root).NavigateIn(apologyName, ItemType.Document));
                        if (!apologyFile.Exists())
                        {
                            var f = isf.CreateFile(apologyFile.Path.PathString);
                            var sw = new StreamWriter(f);
                            sw.Write("When I last updated the app I changed the folder that all of your documents were stored in. This made it look like you lost all of your documents. It was a careless oversight and a huge mistake, and I can promise it won't happen again. You should find all of your files in the lost_files directory. Sorry!");
                            sw.Close();
                        }

                        IsolatedStorageSettings.ApplicationSettings["HasMovedRoot"] = true;
                        IsolatedStorageSettings.ApplicationSettings.Save();
                    }
                }
            }

            // Add test data
            //using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            //{
            //    IsolatedStorageFileStream s1 = isf.CreateFile(rootName + "/new1.doc");
            //    s1.Close();
            //    IsolatedStorageFileStream s2 = isf.CreateFile(rootName + "/new2.doc");
            //    s2.Close();
            //    isf.CreateDirectory(rootName + "/Dir1.dir");
            //    isf.CreateDirectory(rootName + "/Dir2.dir");
            //    isf.CreateDirectory(rootName + "/Dir1.dir/SubDir1.dir");
            //    isf.CreateDirectory(rootName + "/Dir2.dir/SubDir2.dir");
            //    WriteFiles(new string[] { "FileDir1.dir", "FileDir2.dir" });
            //}
        }
Exemple #15
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (_curr == null)
                GetArgs();
            _curr = (Directory)_curr.SwapRoot();
        }
Exemple #16
0
 public Directory(Directory parent, string name)
 {
     _path = parent.Path.NavigateIn(name);
 }
Exemple #17
0
 // Reads information from the incoming UriString to fill class fields
 private void GetArgs()
 {
     string s;
     if (NavigationContext.QueryString.TryGetValue("param", out s))
     {
         Path p = Path.CreatePathFromString(s);
         _curr = new Directory(p);
     }
     else
     {
         IList<object> args = Utils.GetArguments();
         _curr = (Directory)args[0];
     }
 }
Exemple #18
0
        public IActionable Delete()
        {
            if (isTrash)
            {
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    DeleteRecursive(Path, isf);
                }
                return null;
            }
            else // if (!isTrash)
            {
                Directory trash = new Directory(new Path(PathBase.Trash));
                Directory newLoc = new Directory(trash.Path.NavigateIn(Name));
                if (newLoc.Exists())
                    newLoc.Delete();

                this.Move(trash);
                return newLoc;
            }
        }
Exemple #19
0
        // Changes the currently-viewed folder and updates the view
        private void UpdateItems(Action OnCompleted)
        {
            _isUpdatingItems = true;
            _items.Clear();

            // Re-fill ContentBox
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                List<string> dirs = new List<string>();
                foreach (string dir in isf.GetDirectoryNames(_curr.Path.PathString + "/*"))
                    if (!dir.StartsWith("."))
                        dirs.Add(dir);
                dirs.Sort();

                // Add directories
                foreach (string dir in dirs)
                {
                    Directory d = new Directory(_curr.Path.NavigateIn(dir));
                    ListingsListItem li = ListingsListItem.CreateListItem(d);
                    _items.Add(li);
                }

                List<string> docs = new List<string>();
                foreach (string doc in isf.GetFileNames(_curr.Path.PathString + "/*"))
                    if (!doc.StartsWith("."))
                        docs.Add(doc);
                docs.Sort();

                // Add documents
                foreach (string doc in docs)
                {
                    Document d = new Document(_curr.Path.NavigateIn(doc));
                    ListingsListItem li = ListingsListItem.CreateListItem(d);
                    _items.Add(li);
                }
            }

            _isUpdatingItems = false;
            if (_isShowingLoadingNotice)
                UpdateView(OnCompleted);

            RemoveNotice(Notice.Empty);
            RemoveNotice(Notice.Loading);
        }
Exemple #20
0
 private void TryMoveItem(IActionable a, Directory newLoc)
 {
     try
     {
         a.Move(newLoc);
     }
     catch (ActionableException)
     {
         MessageBoxResult r = MessageBox.Show("There is already a document or directory with the same name at this " +
             "location. Tap OK to overwrite this item, or Cancel to skip it.", a.Name, MessageBoxButton.OKCancel);
         if (r == MessageBoxResult.OK)
         {
             (new Directory(newLoc.Path.NavigateIn(a.Name))).Delete();
             TryMoveItem(a, newLoc);
         }
     }
 }
 private void GetArgs()
 {
     _currentDirectory = (Directory)Utils.CreateActionableFromPath(new PathStr(NavigationContext.QueryString["param"]));
 }
Exemple #22
0
        public static string GetNumberedName(string name, Directory parent)
        {
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {

                if (!isf.FileExists(parent.Path.NavigateIn(name + ".txt").PathString) &&
                    !isf.DirectoryExists(parent.Path.NavigateIn(name).PathString))
                    return name;

                int count = 1;
                while (isf.FileExists(parent.Path.NavigateIn(String.Format("{0} ({1}).txt", name, count)).PathString) ||
                       isf.DirectoryExists(parent.Path.NavigateIn(String.Format("{0} ({1})", name, count)).PathString))
                {
                    count++;
                }
                return String.Format("{0} ({1})", name, count);
            }
        }