rendered paste body#include "gui.h"#include <stdlib.h>#include <time.h>#include "misc.h"#include <sys/types.h>#include <dirent.h>#include <string.h>#if !defined (get16bits)#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ +(uint32_t)(((const uint8_t *)(d))[0]) )#endifshort a_isblank(char *cptr){ return ! ((int)cptr[0]);}void printhex(const char *string, int length){ int i; if(length>0){ for(i=0;i<length;i++){ printf("%02x ",string[i]); } }else { for(i=0;string[i];i++){ printf("%02x ",string[i]); } } printf("\nPrinted %i bytes\n",i);}/* A recursive version of g_file_monitor by yours truly *///void (*free_func)(void*)void _vg_file_monitor_directory(const char *basepath, GFileMonitorCallback cb, char *buffer, int last){ GFileMonitor *mon=NULL; DIR *dptr; struct dirent *ent; int start=0; int length = 0; if(buffer == NULL){ buffer = malloc(sizeof(char) * 1024); strcpy(buffer,basepath); start =1; last = strlen(basepath); printf("Start\n"); } length = strlen(buffer); dptr = opendir(buffer); if(!dptr){ buffer[last]='\0'; return; } while( (ent = readdir(dptr)) ){ if(ent->d_type == DT_DIR){ if(strncmp(ent->d_name,".",2)!=0 && strncmp(ent->d_name,"..",3)!=0){ strcat(buffer,"/"); strcat(buffer,ent->d_name); printf("Adding: %s\n",buffer); //mon = g_file_monitor_directory(g_file_new_for_path(buffer), G_FILE_MONITOR_NONE ,NULL,NULL); //g_signal_connect(mon,"changed",G_CALLBACK(cb),NULL); _vg_file_monitor_directory(basepath,cb,buffer,length); } }else if(ent->d_type == DT_REG){ /* Dont care about files */ } } buffer[last]='\0'; closedir(dptr); if(start){ free(buffer); printf("Done\n"); }}void vg_file_monitor_directory(const char *basepath, GFileMonitorCallback cb){ _vg_file_monitor_directory(basepath,cb,NULL,0);}/* Found this on the net, if you wrote it let me know and i'll credit you */unsigned int SuperFastHash (const char * data, int len) {unsigned int hash = len, tmp;int rem; if (len <= 0 || data == NULL) return 0; rem = len & 3; len >>= 2; /* Main loop */ for (;len > 0; len--) { hash += get16bits (data); tmp = (get16bits (data+2) << 11) ^ hash; hash = (hash << 16) ^ tmp; data += 2*sizeof (uint16_t); hash += hash >> 11; } /* Handle end cases */ switch (rem) { case 3: hash += get16bits (data); hash ^= hash << 16; hash ^= data[sizeof (uint16_t)] << 18; hash += hash >> 11; break; case 2: hash += get16bits (data); hash ^= hash << 11; hash += hash >> 17; break; case 1: hash += *data; hash ^= hash << 10; hash += hash >> 1; } /* Force "avalanching" of final 127 bits */ hash ^= hash << 3; hash += hash >> 5; hash ^= hash << 4; hash += hash >> 17; hash ^= hash << 25; hash += hash >> 6; return hash;}GdkPixbuf *vgdk_pixbuf_scale_keep_ratio(GdkPixbuf *buffer_pix, int width, int height){ double orig_width,orig_height; GdkPixbuf *temp = NULL; if(buffer_pix== NULL)return NULL; orig_width = (double) gdk_pixbuf_get_width(buffer_pix); orig_height = (double) gdk_pixbuf_get_height(buffer_pix); if(width){ double scale_height; scale_height = width / (orig_width/orig_height); temp = gdk_pixbuf_scale_simple(buffer_pix,width,(int)scale_height, GDK_INTERP_BILINEAR); }else if(height){ double scale_width; scale_width = (orig_width/orig_height) * height; temp = gdk_pixbuf_scale_simple(buffer_pix,(int)scale_width,height, GDK_INTERP_BILINEAR); }// temp = exo_gdk_pixbuf_scale_ratio(buffer_pix,width); return temp;}GdkPixbuf *vgdk_pixbuf_new_from_memory(unsigned char *data, size_t size){ GInputStream *buffer_stream; buffer_stream = g_memory_input_stream_new_from_data (data,size, NULL); GdkPixbuf *buffer_pix=NULL; buffer_pix = gdk_pixbuf_new_from_stream(buffer_stream,NULL,NULL); return buffer_pix;}GtkWidget *vgtk_image_new_from_memory(unsigned char *data, size_t size,int width, int height){ GdkPixbuf *temp_pix = vgdk_pixbuf_new_from_memory(data,size); GdkPixbuf *buffer_pix=NULL; /* Scale if necessary */ if(width){ buffer_pix = vgdk_pixbuf_scale_keep_ratio(temp_pix,width,0); g_object_unref(temp_pix); }else if(height){ buffer_pix = vgdk_pixbuf_scale_keep_ratio(temp_pix,0,height); g_object_unref(temp_pix); } GtkWidget *img = NULL; img = gtk_image_new_from_pixbuf(buffer_pix); g_object_unref(buffer_pix); // dont need the pix buffer anymore return img; }