Compare commits

2 Commits

Author SHA1 Message Date
439ebe7279 starting to add flipper 2025-03-25 23:25:47 -07:00
2a13827e87 added copytron filemanager and working on flipper 2025-03-25 07:34:15 -07:00
11 changed files with 182 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,2 +1,2 @@
add_executable(${PROJECT_NAME} main.cpp)
add_executable(${PROJECT_NAME} main.cpp copytron.c flipper.c)
target_link_libraries(${PROJECT_NAME} TartLib)

40
source/copytron.c Normal file
View File

@@ -0,0 +1,40 @@
#include "copytron.h"
#include <string.h>
copytron_file copytronFileCreate() {
copytron_file file = {"", 0};
return file;
}
copytron_flips copytronFlipsCreate() {
copytron_flips flips;
flips.file_count = 0;
for(int i = 0; i < 100; i++) {
flips.files[i] = copytronFileCreate();
}
return flips;
}
int copytronAdd(copytron_flips* flips, copytron_file* file) {
for(int i = 0; i < 100; i++) {
if(flips->files[i].file_path_len == 0) {
flips->files[i] = *file;
flips->file_count++;
}
}
return flips->file_count;
}
int copytronRemove(copytron_flips* flips, copytron_file* file) {
for(int i = 0; i < 100; i++) {
if(flips->file_count != 0) {
if(strcmp(flips->files[i].path, file->path)) {
//flips->files[i].path = 0x00;
flips->files[i].file_path_len = 0;
return 0;
}
}
}
return 1;
}

17
source/copytron.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef COPYTRON_H
#define COPYTRON_H
typedef struct {
char path[255];
int file_path_len;
} copytron_file;
typedef struct {
copytron_file files[100];
int file_count;
}copytron_flips;
copytron_file copytronFileCreate();
copytron_flips copytronFlipsCreate();
int copytronAdd(copytron_flips* flips, copytron_file* file);
int copytronRemove(copytron_flips* flips, copytron_file* file);
#endif

46
source/filemanager.c Normal file
View File

@@ -0,0 +1,46 @@
#include "filemanager.h"
#include <string.h>
const char* m_destenation;
const char* m_workingDirectory;
copytron_flips* m_flips;
void SetCurrentDestenation(const char* des) {
m_destenation = des;
}
void SetCurrentWorkingDirectory(const char* workingDir) {
m_workingDirectory = workingDir;
}
const char* GetCurrentWorkingDriectory() {
return m_workingDirectory;
}
const char* GetCurrentDestenation() {
return m_destenation;
}
void SetCopytronFliper(copytron_flips *flips) {
m_flips = flips;
}
void AddDirectory(const char * dir) {
if(strlen(dir) < 256) {
copytron_file file = copytronFileCreate();
strcpy(file.path, dir);
file.path[strlen(file.path)] = '*';
file.file_path_len = strlen(file.path);
copytronAdd(m_flips, &file);
}
}
void AddFile(const char* dir) {
if(strlen(dir) < 256) {
copytron_file file = copytronFileCreate();
strcpy(file.path, dir);
file.file_path_len = strlen(file.path);
copytronAdd(m_flips, &file);
}
}

18
source/filemanager.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef FILEMANAGER_H
#define FILEMANAGER_H
#include "copytron.h"
/// sets the current destenation.
void SetCurrentDestenation(const char*);
const char* GetCurrentDestenation();
/// sets the current working directory.
void SetCurrentWorkingDirectory(const char*);
const char* GetCurrentWorkingDriectory();
void SetCopytronFliper(copytron_flips* flips);
/// Adds a directory
void AddDirectory(const char*);
/// Adds a file
void AddFile(const char*);
#endif

43
source/flipper.c Normal file
View File

@@ -0,0 +1,43 @@
#include "flipper.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char* m_outputPath;
const char* m_workingPath;
flipper_buffer m_outputBuffer;
flipper_buffer m_workingBuffer;
void FlipperWorkingDir(const char* path) {
m_workingPath = path;
}
void FlipperOutputDir(const char* path) {
m_outputPath = path;
}
void _UpdateBuffer(flipper_buffer* buffer, const char* path) {
char command_buffer[1024];
int path_size = strlen(path);
char* command;
memset(command, (path_size + 6) * sizeof(char), sizeof(char));
strcpy(command, "ls ");
strcat(command, path);
strcat(command, " -a");
FILE* f = popen(command,"r");
fseek(f,0L,SEEK_END);
long sz = ftell(f);
fseek(f,0L,SEEK_SET);
fread(command_buffer, sz,0,f);
fclose(f);
free(command);
// do stuff with the command buffer.
}

17
source/flipper.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef FLIPPER_H
#define FLIPPER_H
typedef struct {
char line[255];
} flipper_line;
typedef struct {
flipper_line lins[50];
} flipper_buffer;
void FlipperSetBuffer(const char* path);
void FlipperAdd(flipper_line);
void FlipperRemove(flipper_line);
void FlipperWorkingDir(const char* path);
void FlipperOutputDir(const char* path);
#endif // !FLIPPER_H