Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions es-app/src/FileSorts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ namespace FileSorts
//only games have rating metadata
if(file1->metadata.getType() == GAME_METADATA && file2->metadata.getType() == GAME_METADATA)
{
return file1->metadata.getFloat("rating") < file2->metadata.getFloat("rating");
float r1 = file1->metadata.getFloat("rating"), r2 = file2->metadata.getFloat("rating");
if (r1 != r2)
return r1 < r2;
}

return false;
return compareFileName(file1, file2);
}

bool compareTimesPlayed(const FileData* file1, const FileData* file2)
{
//only games have playcount metadata
if(file1->metadata.getType() == GAME_METADATA && file2->metadata.getType() == GAME_METADATA)
{
return (file1)->metadata.getInt("playcount") < (file2)->metadata.getInt("playcount");
int pc1 = (file1)->metadata.getInt("playcount"), pc2 = (file2)->metadata.getInt("playcount");
if(pc1 != pc2)
return pc1 < pc2;
}

return false;
return compareFileName(file1, file2);
}

bool compareLastPlayed(const FileData* file1, const FileData* file2)
Expand Down
6 changes: 6 additions & 0 deletions es-app/src/Gamelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ void parseGamelist(SystemData* system)
return;
}

/* Set system sort ID */
system->sortId = root.attribute("sortid").as_int(0);

fs::path relativeTo = system->getStartPath();

const char* tagList[2] = { "game", "folder" };
Expand Down Expand Up @@ -197,6 +200,9 @@ void updateGamelist(SystemData* system)
root = doc.append_child("gameList");
}

// Update to the current sort type for this system
root.remove_attribute("sortid");
root.append_attribute("sortid") = std::to_string(system->sortId).c_str();

//now we have all the information from the XML. now iterate through all our games and add information from there
FileData* rootFolder = system->getRootFolder();
Expand Down
6 changes: 3 additions & 3 deletions es-app/src/SystemData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SystemData::SystemData(const std::string& name, const std::string& fullName, con
mName = name;
mFullName = fullName;
mStartPath = startPath;
sortId = 0; /* This may be updated before sorting by stored gamelist data */

//expand home symbol if the startpath contains ~
if(mStartPath[0] == '~')
Expand All @@ -45,7 +46,7 @@ SystemData::SystemData(const std::string& name, const std::string& fullName, con
if(!Settings::getInstance()->getBool("IgnoreGamelist"))
parseGamelist(this);

mRootFolder->sort(FileSorts::SortTypes.at(0));
mRootFolder->sort(FileSorts::SortTypes.at(sortId));

loadTheme();
}
Expand All @@ -61,7 +62,6 @@ SystemData::~SystemData()
delete mRootFolder;
}


std::string strreplace(std::string str, const std::string& replace, const std::string& with)
{
size_t pos;
Expand Down Expand Up @@ -308,7 +308,7 @@ bool SystemData::loadConfig()
continue;
}

//convert path to generic directory seperators
//convert path to generic directory separators
boost::filesystem::path genericPath(path);
path = genericPath.generic_string();

Expand Down
2 changes: 2 additions & 0 deletions es-app/src/SystemData.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class SystemData
// Load or re-load theme.
void loadTheme();

unsigned int sortId;

private:
std::string mName;
std::string mFullName;
Expand Down
6 changes: 5 additions & 1 deletion es-app/src/guis/GuiFastSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ void GuiFastSelect::updateGameListSort()
{
const FileData::SortType& sort = FileSorts::SortTypes.at(mSortId);

FileData* root = mGameList->getCursor()->getSystem()->getRootFolder();
SystemData* system = mGameList->getCursor()->getSystem();
FileData* root = system->getRootFolder();

system->sortId = mSortId; // update system sort setting

root->sort(sort); // will also recursively sort children

// notify that the root folder was sorted
Expand Down
8 changes: 5 additions & 3 deletions es-app/src/guis/GuiGamelistOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui
for(unsigned int i = 0; i < FileSorts::SortTypes.size(); i++)
{
const FileData::SortType& sort = FileSorts::SortTypes.at(i);
mListSort->add(sort.description, &sort, i == 0); // TODO - actually make the sort type persistent
mListSort->add(sort.description, &sort, i == system->sortId);
}

mMenu.addWithLabel("SORT GAMES BY", mListSort);
Expand All @@ -59,8 +59,10 @@ GuiGamelistOptions::GuiGamelistOptions(Window* window, SystemData* system) : Gui

GuiGamelistOptions::~GuiGamelistOptions()
{
// apply sort
FileData* root = getGamelist()->getCursor()->getSystem()->getRootFolder();
// save and apply sort
SystemData* system = getGamelist()->getCursor()->getSystem();
FileData* root = system->getRootFolder();
system->sortId = mListSort->getSelectedId(); // this will break if mListSort isn't in the same order as FileSorts:typesArr
root->sort(*mListSort->getSelected()); // will also recursively sort children

// notify that the root folder was sorted
Expand Down
24 changes: 24 additions & 0 deletions es-app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#ifdef WIN32
#include <Windows.h>
#include <shellapi.h>
#endif

namespace fs = boost::filesystem;
Expand Down Expand Up @@ -338,3 +339,26 @@ int main(int argc, char* argv[])

return 0;
}

#ifdef WIN32
int CALLBACK WinMain(
_In_ HINSTANCE hInstance,
_In_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nCmdShow
)
{
/* Just convert command-line arguments to UTF-8 and call main() */
int argc, i;
LPWSTR *argvW = CommandLineToArgvW(GetCommandLineW(), &argc);
char **argv = new char *[argc];
for (i = 0; i < argc; i++)
{
int len = WideCharToMultiByte(CP_UTF8, 0, argvW[i], -1, NULL, 0, NULL, NULL);
argv[i] = new char[len];
WideCharToMultiByte(CP_UTF8, 0, argvW[i], -1, argv[i], len, NULL, NULL);
}
main(argc, argv);
}

#endif /* WIN32 */
8 changes: 8 additions & 0 deletions es-core/src/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ float round(float num)
}
#endif

#if _MSC_VER >= 1700
FILE iob[] = {*stdin, *stdout, *stderr };
FILE * __iob_func(void)
{
return iob;
}
#endif

Eigen::Affine3f& roundMatrix(Eigen::Affine3f& mat)
{
mat.translation()[0] = round(mat.translation()[0]);
Expand Down
2 changes: 2 additions & 0 deletions es-core/src/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ Eigen::Affine3f roundMatrix(const Eigen::Affine3f& mat);
Eigen::Vector3f roundVector(const Eigen::Vector3f& vec);
Eigen::Vector2f roundVector(const Eigen::Vector2f& vec);

#if _MSC_VER < 1800
float round(float num);
#endif /* _MSC_VER */

std::string getCanonicalPath(const std::string& str);

Expand Down
2 changes: 1 addition & 1 deletion es-core/src/components/OptionListComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ class OptionListComponent : public GuiComponent
onSelectedChanged();
}

private:
unsigned int getSelectedId()
{
assert(mMultiSelect == false);
Expand All @@ -265,6 +264,7 @@ class OptionListComponent : public GuiComponent
return 0;
}

private:
void open()
{
mWindow->pushGui(new OptionListPopup(mWindow, this, mName));
Expand Down