⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windowfilelist.c.orig

📁 上一个上传的有问题,这个是好的。visopsys包括系统内核和GUI的全部SOURCE code ,还包括一些基本的docs文档。里面src子目录对应所有SOURCE code.对于想研究操作系统的朋
💻 ORIG
📖 第 1 页 / 共 2 页
字号:
// //  Visopsys//  Copyright (C) 1998-2007 J. Andrew McLaughlin//  //  This library is free software; you can redistribute it and/or modify it//  under the terms of the GNU Lesser General Public License as published by//  the Free Software Foundation; either version 2.1 of the License, or (at//  your option) any later version.////  This library is distributed in the hope that it will be useful, but//  WITHOUT ANY WARRANTY; without even the implied warranty of//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser//  General Public License for more details.////  You should have received a copy of the GNU Lesser General Public License//  along with this library; if not, write to the Free Software Foundation,//  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.////  windowFileList.c//// This contains functions for user programs to operate GUI components.#include <errno.h>#include <stdio.h>#include <stdlib.h>#include <sys/api.h>#include <sys/window.h>#define FILEBROWSE_CONFIG        "/system/config/filebrowse.conf"#define DEFAULT_FOLDERICON_VAR   "icon.folder"#define DEFAULT_FOLDERICON_FILE  "/system/icons/foldicon.bmp"#define DEFAULT_FILEICON_VAR     "icon.file"#define DEFAULT_FILEICON_FILE    "/system/icons/pageicon.bmp"#define DEFAULT_IMAGEICON_VAR    "icon.image"#define DEFAULT_IMAGEICON_FILE   "/system/icons/imageicon.bmp"#define DEFAULT_EXECICON_VAR     "icon.executable"#define DEFAULT_EXECICON_FILE    "/system/icons/execicon.bmp"#define DEFAULT_OBJICON_VAR      "icon.object"#define DEFAULT_OBJICON_FILE     "/system/icons/objicon.bmp"#define DEFAULT_CONFIGICON_VAR   "icon.config"#define DEFAULT_CONFIGICON_FILE  "/system/icons/conficon.bmp"#define DEFAULT_BOOTICON_VAR     "icon.boot"#define DEFAULT_BOOTICON_FILE    "/system/icons/booticon.bmp"#define DEFAULT_TEXTICON_VAR     "icon.text"#define DEFAULT_TEXTICON_FILE    "/system/icons/texticon.bmp"#define DEFAULT_BINICON_VAR      "icon.binary"#define DEFAULT_BINICON_FILE     "/system/icons/binicon.bmp"typedef struct {  int classFlags;  const char *imageVariable;  const char *imageFile;  image *image;} icon;typedef struct {  file file;  char fullName[MAX_PATH_NAME_LENGTH];  listItemParameters iconParams;  loaderFileClass class;  icon *icon;} fileEntry;static variableList config;static int initialized = 0;// Our list of icon imagesstatic image folderImage;static image fileImage;static image configImage;static image textImage;static image imageImage;static image bootImage;static image execImage;static image objImage;static image binImage;#define FOLDER_ICON \ { 0, DEFAULT_FOLDERICON_VAR, DEFAULT_FOLDERICON_FILE, &folderImage }#define FILE_ICON \ { 0xFFFFFFFF, DEFAULT_FILEICON_VAR, DEFAULT_FILEICON_FILE, &fileImage }static icon folderIcon = FOLDER_ICON;static icon fileIcon = FILE_ICON;static icon iconList[] = {  // These get traversed in order; the first matching file class flags get  // the icon.  So, for example, if you want to make an icon for a type  // of binary file, put it *before* the icon for plain binaries.  { LOADERFILECLASS_CONFIG, DEFAULT_CONFIGICON_VAR, DEFAULT_CONFIGICON_FILE,    &configImage },  { LOADERFILECLASS_TEXT, DEFAULT_TEXTICON_VAR, DEFAULT_TEXTICON_FILE,    &textImage },  { LOADERFILECLASS_IMAGE, DEFAULT_IMAGEICON_VAR, DEFAULT_IMAGEICON_FILE,    &imageImage },  { LOADERFILECLASS_BOOT, DEFAULT_BOOTICON_VAR, DEFAULT_BOOTICON_FILE,    &bootImage },  { LOADERFILECLASS_EXEC, DEFAULT_EXECICON_VAR, DEFAULT_EXECICON_FILE,    &execImage },  { (LOADERFILECLASS_OBJ | LOADERFILECLASS_LIB), DEFAULT_OBJICON_VAR,    DEFAULT_OBJICON_FILE, &objImage },  { LOADERFILECLASS_BIN, DEFAULT_BINICON_VAR, DEFAULT_BINICON_FILE,    &binImage },  // This one goes last, because the flags match every file class.  FILE_ICON};    __attribute__((format(printf, 1, 2)))static void error(const char *format, ...){  // Generic error message code    va_list list;  char *output = NULL;  output = malloc(MAXSTRINGLENGTH);  if (output == NULL)    return;    va_start(list, format);  vsnprintf(output, MAXSTRINGLENGTH, format, list);  va_end(list);  windowNewErrorDialog(NULL, "Error", output);  free(output);}static int loadIcon(const char *variableName, const char *defaultIcon,		    image *theImage){  // Try to load the requested icon, first based on the configuration file  // variable name, then by the default filename.  int status = 0;  char variableValue[MAX_PATH_NAME_LENGTH];  file tmpFile;  // First try the variable  status = variableListGet(&config, variableName, variableValue,			   MAX_PATH_NAME_LENGTH);  if (status >= 0)    defaultIcon = variableValue;  // Try to load the image  status = fileFind(defaultIcon, &tmpFile);  if (status < 0)    return (status);  return (imageLoad(defaultIcon, 0, 0, theImage));}static void getFileIcon(fileEntry *entry){  int count;  entry->icon = &fileIcon;  for (count = 0; count < (int) (sizeof(iconList) / sizeof(icon)); count ++)    {      if (entry->class.flags & iconList[count].classFlags)	{	  entry->icon = &iconList[count];	  break;	}    }  while (entry->icon->image->data == NULL)    {      if (loadIcon(entry->icon->imageVariable, entry->icon->imageFile,		   entry->icon->image) < 0)	{	  if (entry->icon == &fileIcon)	    return;	  entry->icon = &fileIcon;	}      else	break;    }  memcpy(&(entry->iconParams.iconImage), entry->icon->image, sizeof(image));}static int classifyEntry(fileEntry *entry){  // Given a file entry with it's 'file' field filled, classify the file,  // set up the icon image, etc.  int status = 0;  strncpy(entry->iconParams.text, entry->file.name, WINDOW_MAX_LABEL_LENGTH);  switch (entry->file.type)    {    case dirT:      if (!strcmp(entry->file.name, ".."))	strcpy(entry->iconParams.text, "(up)");      entry->icon = &folderIcon;      if (entry->icon->image->data == NULL)	{	  status = loadIcon(entry->icon->imageVariable, entry->icon->imageFile,			    entry->icon->image);	  if (status < 0)	    return (status);	}      memcpy(&(entry->iconParams.iconImage), entry->icon->image,	     sizeof(image));      break;    case fileT:      // Get the file class information      loaderClassifyFile(entry->fullName, &(entry->class));      // Get the the icon for the file      getFileIcon(entry);      break;    case linkT:      if (!strcmp(entry->file.name, ".."))	{	  strcpy(entry->iconParams.text, "(up)");	  entry->icon = &folderIcon;	  if (entry->icon->image->data == NULL)	    {	      status = loadIcon(entry->icon->imageVariable,				entry->icon->imageFile, entry->icon->image);	      if (status < 0)		return (status);	    }	  memcpy(&(entry->iconParams.iconImage), entry->icon->image,		 sizeof(image));	}      break;    default:      break;    }  return (status = 0);}static int changeDirectory(windowFileList *fileList, const char *rawPath){  // Given a directory structure pointer, allocate memory, read all of the  // required information into memory  int status = 0;  char path[MAX_PATH_LENGTH];  char tmpFileName[MAX_PATH_NAME_LENGTH];  int totalFiles = 0;  fileEntry *tmpFileEntries = NULL;  int tmpNumFileEntries = 0;  file tmpFile;  int count;  fileFixupPath(rawPath, path);  // Get the count of files so we can preallocate memory, etc.  totalFiles = fileCount(path);  if (totalFiles < 0)    {      error("Can't access directory \"%s\"", path);      return (totalFiles);    }  // Read the file information for all the files  if (totalFiles)    {      // Get memory for the new entries      tmpFileEntries = malloc(totalFiles * sizeof(fileEntry));      if (tmpFileEntries == NULL)	{	  error("Memory allocation error");	  return (status = ERR_MEMORY);	}        for (count = 0; count < totalFiles; count ++)	{	  if (count == 0)	    status = fileFirst(path, &tmpFile);	  else	    status = fileNext(path, &tmpFile);	  if (status < 0)	    {	      error("Error reading files in \"%s\"", path);	      free(tmpFileEntries);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -