summaryrefslogtreecommitdiff
path: root/src/puzzles
diff options
context:
space:
mode:
Diffstat (limited to 'src/puzzles')
-rw-r--r--src/puzzles/collection.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/puzzles/collection.c b/src/puzzles/collection.c
index ca2743c..a88bae4 100644
--- a/src/puzzles/collection.c
+++ b/src/puzzles/collection.c
@@ -13,6 +13,14 @@
static const char *IMAGE_NAME = "icon.png";
static const float NAME_IN_CARD_RATIO = 0.2f;
+int compare_elements(const void *a, const void *b) {
+ const CollectionElement *elA = (const CollectionElement *)a;
+ const CollectionElement *elB = (const CollectionElement *)b;
+
+ // Sort alphabetically by name
+ return strcmp(elA->path, elB->path);
+}
+
CollectionElementType getTypeFromPath(char *fullPath) {
struct stat st;
if (stat(fullPath, &st) != 0) return COLLECTION_ELEMENT_UNKNOWN;
@@ -65,16 +73,20 @@ char *getName(char *name) {
char buf[1024];
strncpy(buf, name, sizeof(buf));
size_t len = strlen(name);
+ size_t span_start = 0;
+ size_t span_end = 0;
// Cutting a file extention
for (size_t i = 0; i < len; ++i) {
if (buf[i] == '.') {
- buf[i] = 0x0;
- break;
+ if (span_end != 0) span_start = span_end + 1;
+ span_end = i;
}
}
+ if (span_end != 0)
+ buf[span_end] = 0x0;
- return strdup(buf);
+ return strdup(buf + span_start);
}
size_t getElementCount(DIR *dir, CollectionElement *el) {
@@ -136,6 +148,9 @@ void initCollectionFromDir(CollectionElement *el, void (*callback)(CollectionEle
idx += 1;
}
+ if (idx > 1) {
+ qsort(el->children, idx, sizeof(CollectionElement), compare_elements);
+ }
closedir(dir);
}