commit abf384fe
Removed listFiles object. It was not used at the moment and there is a better alternative in PhysFS.
Changed files
| D | source/code/listFiles.cpp before |
| D | source/code/listFiles.h before |
| M | source/code/main.cpp before |
diff --git a/source/code/listFiles.cpp b/source/code/listFiles.cpp
deleted file mode 100644
index 54ad367..0000000
--- a/source/code/listFiles.cpp
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
-===========================================================================
-blockattack - Block Attack - Rise of the Blocks
-Copyright (C) 2005-2012 Poul Sander
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see http://www.gnu.org/licenses/
-
-Source information and contacts persons can be found at
-http://blockattack.net
-===========================================================================
-*/
-
-/*
-listFiles.cpp
-*/
-
-#include "listFiles.h"
-
-using namespace std;
-
-
-void ListFiles::setDirectory(const string& directory) {
- filenames.clear();
-#if defined(_WIN32)
- DWORD dwError;
- string directory2 = directory+"/*";
- hFind = FindFirstFile(directory2.c_str(), &FindFileData);
- if (hFind == INVALID_HANDLE_VALUE) {
- cout << "Invalid file handle. Error is " << GetLastError() << endl;
- }
- else {
- filenames.push_back(FindFileData.cFileName);
- cout << "File: " << FindFileData.cFileName << endl;
- while ((FindNextFile(hFind, &FindFileData) != 0) && FindFileData.cFileName[0]!='.') {
- filenames.push_back(FindFileData.cFileName);
- cout << "File: " << FindFileData.cFileName << endl;
- }
-
- dwError = GetLastError();
- FindClose(hFind);
- if (dwError != ERROR_NO_MORE_FILES) {
- cout << "FindNextFile error. Error is " << dwError << endl;
- }
- }
-#elif defined(__unix__)
- DIR* DirectoryPointer;
- struct dirent* dp;
- //cout << "Will look in: " << directory << endl;
- DirectoryPointer = opendir(directory.c_str());
- if (!DirectoryPointer) {
- return;
- }
- while ( (dp=readdir(DirectoryPointer)) ) {
- string name = (string)(char*)dp->d_name;
- if ( name.at(0) != '.' && !isInList(name) ) {
- filenames.push_back(name);
- }
- }
- closedir(DirectoryPointer);
-
-
-#endif
- startFileNr=FIRST_FILE;
- //Put code here
-}
-
-bool ListFiles::isInList(const string& name) {
- for (int i=0; i< (int)filenames.size(); i++) {
- if (name == filenames.at(i) ) {
- return true;
- }
- }
- return false;
-}
-
-void ListFiles::setDirectory2(const string& dic) {
-#if defined(__unix__)
- DIR* DirectoryPointer;
- struct dirent* dp;
- //cout << "Will look in: " << dic << endl;
- DirectoryPointer = opendir(dic.c_str());
- if (!DirectoryPointer) {
- return;
- }
- while ( (dp=readdir(DirectoryPointer)) ) {
- string name = (string)(char*)dp->d_name;
- if ( name.at(0) != '.' && !isInList(name) ) {
- filenames.push_back(name);
- }
- }
- closedir(DirectoryPointer);
-
- startFileNr=FIRST_FILE;
-#endif
-}
-
-string ListFiles::getFileName(int nr) {
- if (startFileNr+nr< (int)filenames.size()) {
- return filenames[startFileNr+nr];
- }
- else {
- return "";
- }
-}
-
-bool ListFiles::fileExists(int nr) {
- string emptyString="";
- if (startFileNr+nr<(int)filenames.size()) {
- if (filenames[startFileNr+nr]==emptyString) {
- return false;
- }
- else {
- return true;
- }
- }
- else {
- return false;
- }
-}
-
-void ListFiles::back() {
- if (startFileNr>FIRST_FILE) {
- startFileNr = startFileNr-10;
- }
- if (startFileNr<FIRST_FILE) {
- startFileNr = FIRST_FILE;
- }
-}
-
-void ListFiles::forward() {
- if (startFileNr<(int)filenames.size()-FIRST_FILE) {
- startFileNr = startFileNr+10;
- }
-}
-
-string ListFiles::getRandom() {
- int numberOfFiles = filenames.size()-FIRST_FILE+1;
- if (numberOfFiles<1) {
- return "";
- }
- int select = rand()%numberOfFiles;
- return filenames[FIRST_FILE+select];
-}
diff --git a/source/code/listFiles.h b/source/code/listFiles.h
deleted file mode 100644
index a8915cb..0000000
--- a/source/code/listFiles.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-===========================================================================
-blockattack - Block Attack - Rise of the Blocks
-Copyright (C) 2005-2012 Poul Sander
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see http://www.gnu.org/licenses/
-
-Source information and contacts persons can be found at
-http://blockattack.net
-===========================================================================
-*/
-
-//listFiles.h - List files in a given directory, 10 files at a time, at most 250 files
-#include <string.h>
-#include <iostream>
-#include <stdlib.h>
-#if defined(_WIN32)
-#include <windows.h>
-#elif defined(__unix__)
-#include <dirent.h>
-#endif
-#include <string>
-#include <vector>
-
-#if defined (_WIN32)
-#define FIRST_FILE 2
-#else
-#define FIRST_FILE 1
-#endif
-
-class ListFiles
-{
-private:
- int startFileNr; //The first fileto belisted
- std::vector<std::string> filenames;
-#if defined(_WIN32)
- WIN32_FIND_DATA FindFileData;
- HANDLE hFind;
-#endif
- bool isInList(const std::string& name); //The name is already in the list
-public:
- //ListFiles();
- //~ListFiles();
- void setDirectory(const std::string& dictory); //Find file in BlockAttack folder
- void setDirectory2(const std::string& dictory); //Second directory we also look in
- //void setDirecctoryInHome(string dictory); //Find files in home folder (it should work...)
- std::string getFileName(int); //Returns the filename of a file
- bool fileExists(int);
- void forward(); //inclease startFile by 10
- void back(); //decrease startFile by 10
- std::string getRandom(); //Return the name of a random file in the directory, empty if none
-};
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 1a1cd59..06c3114 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -78,7 +78,6 @@ http://www.blockattack.net
#include "highscore.h" //Stores highscores
#include "ReadKeyboard.h" //Reads text from keyboard
#include "joypad.h" //Used for joypads
-#include "listFiles.h" //Used to show files on screen
#include "stats.h" //Saves general stats
//#include "uploadReplay.h" //Takes care of everything libcurl related
@@ -981,92 +980,6 @@ void OpenScoresDisplay() {
}
-//Open a puzzle file
-bool OpenFileDialogbox(int x, int y, char* name) {
- bool done = false; //We are done!
- int mousex, mousey;
- ListFiles lf = ListFiles();
- string folder = (string)SHAREDIR+(string)"/puzzles";
- if (verboseLevel) {
- cout << "Looking in " << folder << endl;
- }
- lf.setDirectory(folder.c_str());
-#ifdef __unix__
- string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles";
- lf.setDirectory2(homeFolder.c_str());
-#endif
- while (!done && !Config::getInstance()->isShuttingDown()) {
- DrawIMG(backgroundImage,screen,0,0);
- DrawIMG(bForward,screen,x+460,y+420);
- nf_button_font.draw(screen, x+20+60, y+420+10, NFont::CENTER, _("Forward"));
- DrawIMG(bBack,screen,x+20,y+420);
- nf_button_font.draw(screen, x+20+60, y+420+10, NFont::CENTER, _("Back"));
- const int nrOfFiles = 10;
- for (int i=0; i<nrOfFiles; i++) {
- NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str());
- }
-
- SDL_Event event;
-
- while ( SDL_PollEvent(&event) ) {
- if ( event.type == SDL_QUIT ) {
- Config::getInstance()->setShuttingDown(5);
- done = true;
- }
-
- if ( event.type == SDL_KEYDOWN ) {
- if ( (event.key.keysym.sym == SDLK_ESCAPE) ) {
- done = true;
- }
-
- if ( (event.key.keysym.sym == SDLK_RIGHT) ) {
- lf.forward();
- }
-
- if ( (event.key.keysym.sym == SDLK_LEFT) ) {
- lf.back();
- }
- }
-
- } //while(event)
-
- SDL_GetMouseState(&mousex,&mousey);
-
- // If the mouse button is released, make bMouseUp equal true
- if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) {
- bMouseUp=true;
- }
-
- if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) {
- bMouseUp = false;
-
- //The Forward Button:
- if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) ) {
- lf.forward();
- }
-
- //The back button:
- if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) ) {
- lf.back();
- }
-
- for (int i=0; i<10; i++) {
- if ( (mousex>x+10) && (mousex<x+480) && (mousey>y+10+i*36) && (mousey<y+10+i*36+32) ) {
- if (lf.fileExists(i)) {
- strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29)
- done=true; //The user have, clicked the purpose of this function is now complete
- }
- }
- }
- }
-
- mouse.Draw(screen, SDL_GetTicks(), mousex, mousey);
- SDL_RenderPresent(screen); //Update screen
- }
- return true;
-}
-
-
//Draws the balls and explosions
static void DrawBalls() {
for (int i = 0; i< maxNumberOfBalls; i++) {
@@ -1452,23 +1365,6 @@ int PuzzleLevelSelect(int Type) {
return levelNr;
}
-//This function will promt for the user to select another file for puzzle mode
-void changePuzzleLevels() {
- char theFileName[30];
- snprintf(theFileName, sizeof(theFileName), "%s", PuzzleGetName().c_str());
- for (int i=PuzzleGetName().length(); i<30; i++) {
- theFileName[i]=' ';
- }
- theFileName[29]=0;
- if (OpenFileDialogbox(200,100,theFileName)) {
- for (int i=28; ((theFileName[i]==' ')&&(i>0)); i--) {
- theFileName[i]=0;
- }
- PuzzleSetName(theFileName);
- }
-
-}
-
static BlockGameSdl* player1;
static BlockGameSdl* player2;