int Unix_dir_list::is_empty() { DIR* dh; struct dirent* current_entry; dh = opendir(path); if (dh == 0) { _error = errno; return 1; } current_entry = readdir(dh); while (current_entry != 0) { if (valid_file_name(current_entry->d_name)) { closedir(dh); return 0; } current_entry = readdir(dh); } closedir(dh); return 1; }
int Windows_dir_list::is_empty() { int isEmpty = 1; char new_path[_MAX_PATH+10]; /* Flawfinder: ignore */ HANDLE f_handle = INVALID_HANDLE_VALUE; WIN32_FIND_DATA f_info; SafeSprintf(new_path, _MAX_PATH+10, "%s/*.*", _path); f_handle = FindFirstFile(OS_STRING(new_path), &f_info); if (f_handle == INVALID_HANDLE_VALUE) { do { if (valid_file_name(OS_STRING(f_info.cFileName))) isEmpty = 0; } while (isEmpty && (FindNextFile(f_handle, &f_info) != 0)); } else _error = EINVAL; FindClose(f_handle); return isEmpty; }
virtual void Execute(LPCSTR args) { #if 0 if (!Level().autosave_manager().ready_for_autosave()) { Msg ("! Cannot save the game right now!"); return; } #endif if(!IsGameTypeSingle()){ Msg("for single-mode only"); return; } if(!g_actor || !Actor()->g_Alive()) { Msg("cannot make saved game because actor is dead :("); return; } string_path S,S1; S[0] = 0; //. sscanf (args ,"%s",S); strcpy_s (S,args); #ifdef DEBUG CTimer timer; timer.Start (); #endif if (!xr_strlen(S)){ strconcat (sizeof(S),S,Core.UserName,"_","quicksave"); NET_Packet net_packet; net_packet.w_begin (M_SAVE_GAME); net_packet.w_stringZ(S); net_packet.w_u8 (0); Level().Send (net_packet,net_flags(TRUE)); }else{ if(!valid_file_name(S)){ Msg("invalid file name"); return; } NET_Packet net_packet; net_packet.w_begin (M_SAVE_GAME); net_packet.w_stringZ(S); net_packet.w_u8 (1); Level().Send (net_packet,net_flags(TRUE)); } #ifdef DEBUG Msg ("Game save overhead : %f milliseconds",timer.GetElapsed_sec()*1000.f); #endif SDrawStaticStruct* _s = HUD().GetUI()->UIGame()->AddCustomStatic("game_saved", true); _s->m_endTime = Device.fTimeGlobal+3.0f;// 3sec string_path save_name; strconcat (sizeof(save_name),save_name,*CStringTable().translate("st_game_saved"),": ", S); _s->wnd()->SetText (save_name); strcat (S,".dds"); FS.update_path (S1,"$game_saves$",S); #ifdef DEBUG timer.Start (); #endif MainMenu()->Screenshot (IRender_interface::SM_FOR_GAMESAVE,S1); #ifdef DEBUG Msg ("Screenshot overhead : %f milliseconds",timer.GetElapsed_sec()*1000.f); #endif }