11// File: SafeNotes/Utilities.cs
22using System ;
33using System . IO ;
4+ using System . Linq ;
45
56namespace SafeNotes
67{
@@ -10,27 +11,16 @@ private void UpdateEntriesCountAndSaveToFile()
1011 {
1112 // Update the savedEntriesCount label
1213 SavedEntriesCount . Text = "Saved entries: " + EntriesListBox . Items . Count . ToString ( ) ;
13-
14- string exeDirectory = AppDomain . CurrentDomain . BaseDirectory ;
15- string filePath = Path . Combine ( exeDirectory , "entries.txt" ) ;
16-
17- // Now save all entries to a txt file in the location of the application's .exe
18- string [ ] entries = new string [ EntriesListBox . Items . Count ] ;
19- for ( int i = 0 ; i < EntriesListBox . Items . Count ; i ++ )
20- {
21- // Do not include "ListViewItem:" in the txt file, instead say Entry # and the number of the entry
22- entries [ i ] = EntriesListBox . Items [ i ] . ToString ( ) . Replace ( "ListViewItem: {" , "" ) . Replace ( "}" , "" ) ;
23- }
24- System . IO . File . WriteAllLines ( filePath , entries ) ;
2514 }
2615
2716 private string FindManagerPath ( string managerName )
2817 {
2918 string [ ] paths = {
30- "C:\\ Program Files\\ " + managerName + " \\ " + managerName + ".exe" ,
31- "C:\\ Program Files (x86)\\ " + managerName + " \\ " + managerName + ".exe"
19+ Path . Combine ( "C:\\ Program Files" , managerName , managerName + ".exe" ) ,
20+ Path . Combine ( "C:\\ Program Files (x86)" , managerName , managerName + ".exe" )
3221 } ;
3322
23+ // Check in Program Files and Program Files (x86)
3424 foreach ( string path in paths )
3525 {
3626 if ( File . Exists ( path ) )
@@ -39,6 +29,18 @@ private string FindManagerPath(string managerName)
3929 }
4030 }
4131
32+ // Check AppData\Local and all subdirectories
33+ string appDataPath = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , managerName ) ;
34+ if ( Directory . Exists ( appDataPath ) )
35+ {
36+ string [ ] exeFiles = Directory . GetFiles ( appDataPath , "*.exe" , SearchOption . AllDirectories )
37+ . Where ( f => Path . GetFileName ( f ) . ToLower ( ) . Contains ( managerName . ToLower ( ) ) )
38+ . ToArray ( ) ;
39+ if ( exeFiles . Length > 0 )
40+ {
41+ return exeFiles [ 0 ] ;
42+ }
43+ }
4244 return null ;
4345 }
4446
@@ -47,31 +49,31 @@ private string GetManagerArgs(string managerName)
4749 switch ( managerName )
4850 {
4951 case "Bitwarden" :
50- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
52+ return "--password" + UserPassword . Text ;
5153 case "KeePass Password Safe 2" :
52- return "\" -user= \" " + UserPassword . Text + " \" - pw=\" " + UserConfirmPassword . Text + "\" " ;
54+ return "\" - pw=\" " + UserPassword . Text + "\" " ;
5355 case "1Password" :
54- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
56+ return "--password" + UserPassword . Text ;
5557 case "LastPass" :
56- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
58+ return "--password" + UserPassword . Text ;
5759 case "ProtonPass" :
58- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
60+ return "--password" + UserPassword . Text ;
5961 case "NordPass" :
60- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
62+ return "--password" + UserPassword . Text ;
6163 case "Dashlane" :
62- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
64+ return "--password" + UserPassword . Text ;
6365 case "Zoho Vault" :
64- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
66+ return "--password" + UserPassword . Text ;
6567 case "RoboForm" :
66- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
68+ return "--password" + UserPassword . Text ;
6769 case "Sticky Password" :
68- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
70+ return "--password" + UserPassword . Text ;
6971 case "Keeper" :
70- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
72+ return "--password" + UserPassword . Text ;
7173 case "Enpass" :
72- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
74+ return "--password" + UserPassword . Text ;
7375 case "Total Password" :
74- return "--username " + UserPassword . Text + " -- password " + UserConfirmPassword . Text ;
76+ return "--password" + UserPassword . Text ;
7577 default :
7678 return null ;
7779 }
0 commit comments