void Settings::Load() { Directory appDataDir = GetAppDataDir(); if (appDataDir.Exists()) { File config; config.SetLocation(appDataDir.Location().OriginalString() + "/config.txt"); FileStream fs; if (config.Exists()) { AutoPointerArray<UInt8> buf(new UInt8[config.Size()], config.Size()); if (fs.Open(config.Location(), FileAccessMode::Read, FileAccessPriority::ReadThroughput)) { fs.Read(buf.Get(), 0, buf.Size()); fs.Close(); for (Size i = 0, s = 0; i < buf.Size(); ++i) if (buf[i] == '\n') { String line = String(reinterpret_cast<const char*>(&buf[s]), i - s); AutoPointerArray<String> keyValue = line.Split(String("=")); if (keyValue.Count() == 2) { const char* key = StringCache::Find(keyValue[0]); if (key == 0) key = keyValue[0].c_str(); m_PImpl->m_Data[key] = keyValue[1]; } s = i+1; } } } } }
int ls_main( int argc, char **argv ) { char *node = NULL; if ( argc == 1 ) node = strdup("/"); if ( argc == 2 ) node = strdup( argv[1] ); if ( node == NULL ) return -1; Directory *dir = new Directory( node ); if ( dir->Exists() == false ) { printf("%s\n","directory does not exist."); } char *front = (char*)malloc( strlen(node) + 2 ); strcpy( front, node ); if ( front[strlen(front) - 1] != '/' ) strcat( front, "/" ); char *entry = NULL; while ((entry = dir->NextEntry()) != NULL ) { char *complete = (char*)malloc(strlen(front) + strlen(entry) + 5 ); strcpy( complete, front ); strcat( complete, entry ); int size = -1; File *temp = new File( complete ); if ( temp->Open() >= 0 ) { size = temp->Size(); temp->Close(); } delete temp; printf("%5s%10i %s\n", ". ", size, entry ); free( complete ); } free( front ); printf("%i%s\n", dir->CountEntries(), " files."); delete dir; free( node ); return 0; }
bool CommanderWindow::Refresh() { cleanPath(); list->Empty(); const char *path = input->Text(); Directory *dir = new Directory( path ); if ( dir->Exists() == false ) { delete dir; Draw( Bounds() ); return false; } char *entry = NULL; while ((entry = dir->NextEntry()) != NULL ) { char *complete = (char*)malloc( strlen(path) + strlen(entry) + 2 ); strcpy( complete, path ); strcat( complete, entry ); int size = -1; File *temp = new File( complete ); if ( temp->Open() >= 0 ) { size = temp->Size(); temp->Close(); } delete temp; list->AddItem( new StringItem( entry ) ); free( complete ); } Draw( Bounds() ); delete dir; return true; }
void Settings::Save() { Directory appDataDir = GetAppDataDir(); if (!appDataDir.Exists()) appDataDir.CreateNewDirectory(); auto it = m_PImpl->m_Data.Begin(); auto end = m_PImpl->m_Data.End(); File config; config.SetLocation(appDataDir.Location().OriginalString() + "/config.txt"); config.CreateNewFile(); FileStream fs; if (fs.Open(config.Location(), FileAccessMode::Write, FileAccessPriority::DelayReadWrite)) { for (; it != end; ++it) { String buf = String::UnsafeStringCreation(it->first) + "=" + it->second + "\n"; fs.Write(reinterpret_cast<const UInt8*>(buf.c_str()), 0, buf.Length()); } fs.Close(); } }