1717using Microsoft . AppCenter . Analytics ;
1818using Microsoft . AppCenter . Crashes ;
1919using Windows . UI . Xaml . Media ;
20+ using Files . Filesystem ;
21+ using System . IO ;
22+ using System . Linq ;
23+ using System . Collections . ObjectModel ;
24+ using Windows . Devices . Enumeration ;
25+ using System . Text . RegularExpressions ;
2026
2127namespace Files
2228{
@@ -76,6 +82,120 @@ public App()
7682
7783 this . RequestedTheme = SettingsPages . Personalization . TV . ThemeValue ;
7884 //Debug.WriteLine("!!Requested Theme!!" + RequestedTheme.ToString());
85+
86+ if ( localSettings . Values [ "FavoritesDisplayed_Start" ] == null )
87+ {
88+ localSettings . Values [ "FavoritesDisplayed_Start" ] = true ;
89+ }
90+
91+ if ( localSettings . Values [ "RecentsDisplayed_Start" ] == null )
92+ {
93+ localSettings . Values [ "RecentsDisplayed_Start" ] = true ;
94+ }
95+
96+ if ( localSettings . Values [ "DrivesDisplayed_Start" ] == null )
97+ {
98+ localSettings . Values [ "DrivesDisplayed_Start" ] = false ;
99+ }
100+
101+ if ( localSettings . Values [ "FavoritesDisplayed_NewTab" ] == null )
102+ {
103+ localSettings . Values [ "FavoritesDisplayed_NewTab" ] = true ;
104+ }
105+
106+ if ( localSettings . Values [ "RecentsDisplayed_NewTab" ] == null )
107+ {
108+ localSettings . Values [ "RecentsDisplayed_NewTab" ] = true ;
109+ }
110+
111+ if ( localSettings . Values [ "DrivesDisplayed_NewTab" ] == null )
112+ {
113+ localSettings . Values [ "DrivesDisplayed_NewTab" ] = false ;
114+ }
115+
116+ FindDrives ( ) ;
117+ //DeviceWatcher watcher = DeviceInformation.CreateWatcher();
118+ //watcher.Added += (sender, info) => FindDrives();
119+ //watcher.Removed += (sender, info) => FindDrives();
120+ //watcher.Start();
121+ }
122+
123+ private async void FindDrives ( )
124+ {
125+ foundDrives . Clear ( ) ;
126+ var knownRemDevices = new ObservableCollection < string > ( ) ;
127+ foreach ( var f in await KnownFolders . RemovableDevices . GetFoldersAsync ( ) )
128+ {
129+ var path = f . Path ;
130+ knownRemDevices . Add ( path ) ;
131+ }
132+
133+ var driveLetters = DriveInfo . GetDrives ( ) . Select ( x => x . RootDirectory . Root ) . ToList ( ) . OrderBy ( x => x . Root . FullName ) . ToList ( ) ;
134+
135+ if ( ! driveLetters . Any ( ) ) return ;
136+
137+ driveLetters . ForEach ( async roots =>
138+ {
139+ try
140+ {
141+ //if (roots.Name == @"C:\") return;
142+ var content = string . Empty ;
143+ string icon ;
144+ if ( knownRemDevices . Contains ( roots . Name ) )
145+ {
146+ content = $ "Removable Drive ({ roots . Name } )";
147+ icon = "\uE88E " ;
148+ }
149+ else
150+ {
151+ content = $ "Local Disk ({ roots . Name } )";
152+ icon = "\uEDA2 " ;
153+ }
154+ StorageFolder drive = await StorageFolder . GetFolderFromPathAsync ( roots . Name ) ;
155+ var retrivedProperties = await drive . Properties . RetrievePropertiesAsync ( new string [ ] { "System.FreeSpace" , "System.Capacity" } ) ;
156+
157+ ulong totalSpaceProg = 0 ;
158+ ulong freeSpaceProg = 0 ;
159+ string free_space_text = "Unknown" ;
160+ string total_space_text = "Unknown" ;
161+ Visibility capacityBarVis = Visibility . Visible ;
162+ try
163+ {
164+ var sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . GigaBytes ;
165+ freeSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
166+
167+ sizeAsGBString = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . GigaBytes ;
168+ totalSpaceProg = Convert . ToUInt64 ( sizeAsGBString ) ;
169+
170+
171+ free_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.FreeSpace" ] ) . ToString ( ) ;
172+ total_space_text = ByteSizeLib . ByteSize . FromBytes ( ( ulong ) retrivedProperties [ "System.Capacity" ] ) . ToString ( ) ;
173+ }
174+ catch ( UnauthorizedAccessException )
175+ {
176+ capacityBarVis = Visibility . Collapsed ;
177+ }
178+ catch ( NullReferenceException )
179+ {
180+ capacityBarVis = Visibility . Collapsed ;
181+ }
182+
183+ foundDrives . Add ( new DriveItem ( )
184+ {
185+ driveText = content ,
186+ glyph = icon ,
187+ maxSpace = totalSpaceProg ,
188+ spaceUsed = totalSpaceProg - freeSpaceProg ,
189+ tag = roots . Name ,
190+ progressBarVisibility = capacityBarVis ,
191+ spaceText = free_space_text + " free of " + total_space_text ,
192+ } ) ;
193+ }
194+ catch ( UnauthorizedAccessException e )
195+ {
196+ Debug . WriteLine ( e . Message ) ;
197+ }
198+ } ) ;
79199 }
80200
81201 public static Windows . UI . Xaml . UnhandledExceptionEventArgs exceptionInfo { get ; set ; }
@@ -96,7 +216,7 @@ private async void App_UnhandledException(object sender, Windows.UI.Xaml.Unhandl
96216
97217 public static PasteState PS { get ; set ; } = new PasteState ( ) ;
98218 public static List < string > pathsToDeleteAfterPaste = new List < string > ( ) ;
99-
219+ public static ObservableCollection < DriveItem > foundDrives = new ObservableCollection < DriveItem > ( ) ;
100220
101221 /// <summary>
102222 /// Invoked when the application is launched normally by the end user. Other entry points
0 commit comments