Exemplo n.º 1
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;
            }
        }
Exemplo n.º 2
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" });
            //}
        }