Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <string.h>
- #include "hacks.h"
- typedef struct
- {
- char *folder;
- char *filePath;
- char *fileName;
- } MediaInfo;
- typedef struct
- {
- MediaInfo *fileInfo;
- int seasons;
- } TvShow;
- typedef struct
- {
- void *data;
- struct Node *next;
- struct Node *prev;
- } Node;
- typedef struct
- {
- Node *head;
- Node *tail;
- int len;
- } LinkedList;
- typedef struct
- {
- char *contents;
- int len;
- } String;
- const char MOVIES_LOCATION[] = "G:\\Videos\\Movies\\";
- const char TVSHOWS_LOCATION[] = "G:\\Videos\\TV Shows\\";
- const char GAMES_LOCATION[] = "D:\\Games\\";
- LinkedList movies;
- LinkedList games;
- LinkedList tvShows;
- Node *createEmptyNode(void)
- {
- Node *n = malloc(sizeof(int) * 3);
- n->data = null;
- n->next = null;
- n->prev = null;
- }
- MediaInfo *createEmptyMediaInfo(void)
- {
- MediaInfo *mi = malloc(sizeof(MediaInfo));
- mi->fileName = null;
- mi->filePath = null;
- mi->folder = null;
- }
- TvShow *createEmptyTvShow(void)
- {
- TvShow *tv = malloc(sizeof(TvShow));
- tv->fileInfo = null;
- tv->seasons = null;
- }
- String *createEmptyString(void) {
- String *s = malloc(sizeof(String));
- s->contents = malloc(sizeof(char) * 15);
- strcpy(s->contents, "");
- s->len = 15;
- }
- LinkedList linkedList_create(void)
- {
- Node *head = null;
- Node *tail = null;
- LinkedList list = {head, tail, 0};
- return list;
- }
- LinkedList linkedList_add(LinkedList list, void *data)
- {
- Node *cur = list.head;
- if(list.head != null)
- {
- while(cur->next != null)
- cur = cur->next;
- Node *next = createEmptyNode();
- next->data = malloc(sizeof(data));
- next->data = data;
- next->prev = cur;
- cur->next = next;
- }
- else
- {
- Node *head = createEmptyNode();
- head->data = malloc(sizeof(data));
- head->data = data;
- list.head = head;
- }
- list.len += 1;
- return list;
- }
- void *linkedList_get(LinkedList list, int index)
- {
- Node *cur = list.head;
- int i = 0;
- if(index != 0)
- {
- while(cur->next != null && i < index)
- {
- cur = cur->next;
- i++;
- }
- }
- if(index == i)
- return cur->data;
- return null;
- }
- LinkedList getFilesInDir(char* dir, LinkedList list)
- {
- WIN32_FIND_DATAA find;
- HANDLE hFile;
- char filter[150];
- MediaInfo *mi = malloc(sizeof(MediaInfo));
- strcpy(filter, dir);
- strcat(filter, "*.*");
- if((hFile=FindFirstFile(filter, &find)) != INVALID_HANDLE_VALUE)
- {
- while(FindNextFile(hFile, &find))
- {
- char* filename = malloc(sizeof(char) * (strlen(find.cFileName) + 1));
- char* filepath = malloc(sizeof(char) * (strlen(dir) + strlen(find.cFileName) + 1));
- strcpy(filename, find.cFileName);
- strcpy(filepath, dir);
- strcat(filepath, filename);
- if(strcmp(filename, "..") && (strstr(filename, ".") == null))
- {
- mi->fileName = filename;
- mi->filePath = filepath;
- mi->folder = dir;
- list = linkedList_add(list, mi);
- mi = createEmptyMediaInfo();
- }
- }
- FindClose(hFile);
- }
- else
- printf("%s: file(s) not found\n", filter);
- return list;
- }
- LinkedList getTvShows(LinkedList list)
- {
- LinkedList tvShowFolders = getFilesInDir(TVSHOWS_LOCATION, linkedList_create());
- LinkedList _tmpSeasons;
- MediaInfo *mi;
- TvShow *tv = createEmptyTvShow();
- int i = 0;
- while(i < tvShowFolders.len)
- {
- mi = linkedList_get(tvShowFolders, i);
- tv->fileInfo = mi;
- char *tvShowFolder = malloc(sizeof(char) * (strlen(mi->filePath) + 2));
- strcpy(tvShowFolder, mi->filePath);
- strcat(tvShowFolder, "\\");
- _tmpSeasons = getFilesInDir(tvShowFolder, linkedList_create());
- tv->seasons = _tmpSeasons.len;
- list = linkedList_add(list, tv);
- tv = linkedList_get(list, 0);
- tv = createEmptyTvShow();
- mi = createEmptyMediaInfo();
- i++;
- }
- return list;
- }
- String *string_concat(String *s, char *str) {
- int len = strlen(s->contents) + strlen(str);
- if(len > s->len)
- realloc(s->contents, sizeof(char));
- if(s->contents == "")
- strcpy(s->contents, str);
- else
- strcat(s->contents, str);
- return s;
- }
- int main()
- {
- int i = 0;
- MediaInfo *mi;
- TvShow *tv;
- int size = 0;
- char *_tmp;
- String *data = createEmptyString();
- STARTUPINFO si;
- PROCESS_INFORMATION pi;
- ZeroMemory( &si, sizeof(si) );
- si.cb = sizeof(si);
- ZeroMemory( &pi, sizeof(pi) );
- movies = getFilesInDir(MOVIES_LOCATION, linkedList_create());
- games = getFilesInDir(GAMES_LOCATION, linkedList_create());
- tvShows = getTvShows(linkedList_create());
- while(i < movies.len) {
- data = string_concat(data, "Movie:");
- mi = linkedList_get(movies, i);
- data = string_concat(data, mi->fileName);
- data = string_concat(data, ";:;");
- i++;
- }
- i = 0;
- while(i < games.len) {
- data = string_concat(data, "Game:");
- mi = linkedList_get(movies, i);
- data = string_concat(data, mi->fileName);
- data = string_concat(data, ";:;");
- i++;
- }
- i = 0;
- while(i < tvShows.len) {
- data = string_concat(data, "TvShow:");
- tv = linkedList_get(tvShows, i);
- mi = tv->fileInfo;
- data = string_concat(data, mi->fileName);
- data = string_concat(data, "Seasons:");
- data = string_concat(data, tv->seasons);
- data = string_concat(data, ";:;");
- i++;
- }
- printf(data->contents);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement