Exemple #1
0
void aboutInit()
{
  char buf[128];
  list_t* txt;
  listItem* it;
  FILE* fp = fopen( DATADIR"data/about.txt", "r");

  if(!fp)
  {
    printf("Couldn't open "DATADIR"data/about.txt\n");
       return;

  }
  txt = listInit(NULL);

  while( fgets(buf, 128, fp ) )
  {
    int l = strlen(buf);
    it = listAppendData(txt, malloc( l+1 ) );
    strcpy( (char*)(it->data), buf );
  }

  numLines = txt->count;
  lines = malloc( sizeof(char*)*numLines );
  listAddToArray((void*)lines,txt);
  listFree(txt);
}
void aboutInit()
{
  char buf[128];
  list_t* txt;
  listItem* it;
  FILE* fp = android_fopen("data/about.txt", "r");

  if(!fp)
  {
	SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,  "Couldn't open data/about.txt");
    return;

  }
  txt = listInit(NULL);

  while( fgets(buf, 128, fp ) )
  {
    int l = strlen(buf);
    it = listAppendData(txt, malloc( l+1 ) );
    strcpy( (char*)(it->data), buf );
  }

  numLines = txt->count;
  lines = malloc( sizeof(char*)*numLines );
  listAddToArray((void*)lines,txt);
  listFree(txt);
}
list_t* listAddFromArray(list_t* list, void** data, int count )
{
  int i;
  for(i=0; i < count; i++)
  {
    listAppendData(list, data[i]);
  }
  return(list);
}
int packAdd(const char* packDir, int isDLC)
{
  char* buf = malloc(sizeof(char)*2048);
  char* buf2= malloc(sizeof(char)*1024);
  char* val = malloc(sizeof(char)*1024);
  char* set = malloc(sizeof(char)*1024);

  //This block is for playlists
  list_t* playList=0;
  listItem* li=0;
  playListItem* pli=0;
  int i; //Counter

  FILE* f=0;
  packInfoType* ti = malloc(sizeof(packInfoType));
  ti->lives=3; //Default 3 lives, if pack do not define another number.
  ti->isDLC=isDLC;

  //Any levels? (Packs are invalid without a levels folder and atleast one level)
  sprintf(buf, "%s/levels/level000.wzp", packDir);

  //Initialize list for playlist
  playList = listInit(_freePlaylistItem);

  //Open packs/packname/info.ini
  sprintf(buf, "%s/info.ini", packDir);
  f = android_fopen(buf, "r");
  if(f)
  {
    while( fgets(buf, 128, f) )
    {
      stripNewLine(buf);
      if(splitVals('=',buf,set,val))
      {
        if(strcmp("author", set)==0)
        {
          ti->author = malloc( sizeof(char)*(strlen(val)+1+3) );
          sprintf(ti->author, "By %s", val);
        } else
        if(strcmp("packname", set)==0)
        {
          ti->name = malloc( sizeof(char)*(strlen(val)+1) );
          strcpy(ti->name,val);
        } else
        if(strcmp("comment", set)==0)
        {
          ti->comment = malloc( sizeof(char)*(strlen(val)+1+1) );
          sprintf(ti->comment, "-%s", val);
        } else
        if(strcmp("mus", set)==0)
        {
          //mus=00,song
          if( splitVals(',',val, buf,set ) && splitVals('-',buf,val,buf2) )
          {
              //val= from buf2=to set=song name
              pli = malloc( sizeof( playListItem ) );
              pli->from=atoi(val);
              pli->to=atoi(buf2);
              pli->song=malloc(sizeof(char)*strlen(set)+1);
              strcpy( pli->song, set );
              listAppendData( playList, (void*)pli );
          } else {
            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "   Playlist entry format is mus=XX-XX,song name.ogg where XX-XX is a level range.\n");
          }
        } else
        if(strcmp("lives", set)==0)
        {
          ti->lives = atoi(val);
        }
      } //Found =
    } //reading file

    //Close the info file.
    fclose(f);
  } else {
    //Fall back if no file was found.
    SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: '%s' not found, using defaults.\n",buf);
    ti->author = malloc( sizeof(char)* 20 );
    strcpy(ti->author, "info.ini not found");
    ti->comment=ti->author;
    ti->name = malloc( sizeof(char)*(strlen(packDir)+1) );
    strcpy(ti->name, packDir);
  }


  //Set path
  ti->path = malloc( sizeof(char)*(strlen(packDir)+1) );
  strcpy(ti->path,packDir);

  //Set pack icon
  sprintf(buf, "%s/icon.png", packDir);
  ti->icon = loadImg(buf);
  if(!ti->icon)
  {
    ti->icon = loadImg( "data/noicon.png" );
  }

  //Check if pack have a "finished" icon.
  sprintf(buf, "%s/finished.png", packDir);

  //Set ps.cp before entering makeLevelist, it makes use of packGetFile
  ps.cp = ti;

  //Add levels.
  ti->levels=0;
  ti->levels=makeLevelList(packDir); //makeLevelList looks in packDir/levels/

  //set number of levels in pack
  ti->numLevels = ti->levels->count - 1  ; //The last level does not count (because it is just a "completed" screen).


  //Add to list of packages
  listAppendData( ps.packs, (void*)ti );

  //Increase number of available packages
  ps.numPacks++;

  //Put playlist songs into levelfiles.
  li=&playList->begin;
  while( LISTFWD(playList,li) )
  {
    pli=(playListItem*)li->data;

    for(i=0; i<ti->numLevels;i++)
    {
      if(i >= pli->from && i <= pli->to)
      {
        levelInfo(i)->musicFile = malloc( sizeof(char)*strlen(pli->song)+1 );
        strcpy(levelInfo(i)->musicFile, pli->song);
      }
    }
  }

  //Clear playlist data
  listFree( playList );

  free(buf);
  free(buf2);
  free(val);
  free(set);

  return(ps.numPacks-1);
}
void packScanDir( const char* path, list_t* dirList )
{
  struct dirent *pent;
  struct stat st;
  char* buf=malloc(sizeof(char)*2048);
  DIR *pdir= opendir( path );

  if(pdir)
  {
    while( (pent=readdir(pdir)) )
    {
      //We're not going to read hidden files or . / ..
      if(pent->d_name[0] != '.')
      {
        sprintf(buf, "%s/%s",path,pent->d_name);
        if(stat(buf, &st)==0)
        {
          if( (st.st_mode&S_IFDIR)==S_IFDIR )
          {
            //Ignore the "wizznic" directory since it's allready added.
            if(strcmp( buf, "packs/000_wizznic" ) != 0)
            {
              char* pdstr = malloc( sizeof(char)*strlen(buf)+1 );
              strcpy( pdstr, buf );
              listAppendData( dirList, (void*)pdstr );
            }
          } else if(  (st.st_mode&S_IFREG) )
          {
            //It's a file, let's try and see if it's a bundle.
            int l = strlen(buf);
            if( l > 4 && strcasecmp( &buf[l-4] ,".wiz" )==0 )
            {

              l = debundle( buf, getUsrPackDir() );

              if( l == BUNDLE_SUCCESS )
              {
                SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Installed bundle '%s'.\n", buf);
                char* pdstr = malloc( sizeof(char)*strlen(buf)+1 );
                strcpy( pdstr, bundlePath() );
                listAppendData( dirList, (void*)pdstr );
                unlink( buf );
              } else if( l == BUNDLE_FAIL_CORRUPT )
              {
                SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "The bundle file '%s' is corrupt, deleting it.\n", buf);
                unlink( buf );
              } else if( l == BUNDLE_FAIL_UNSUPPORTED_VERSION )
              {
                SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "The bundle file '%s' is not supported by this version of Wizznic, please try and update Wizznic.\n", buf);
              } else if( l == BUNDLE_FAIL_DIR_EXISTS )
              {
                SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "The bundle file '%s' has already been installed.\n", buf);
              }

              bundlePathReset();
            }

          }
        } else {
          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "packScanDir(); Error: stat('%s') failed!\n", buf);
        }
      }
    }
    closedir(pdir);
  }

  free(buf);
}
Exemple #6
0
void initCredits(SDL_Surface* screen)
{
  msgList=listInit(_freeCreditListItem);
  listAppendData(msgList, (void*)initMsg("Website","wizznic.org", screen));
  listAppendData(msgList, (void*)initMsg("Code/Gfx/Sfx","Jimmy Christensen", screen));
  listAppendData(msgList, (void*)initMsg("Gfx","ViperMD", screen));
  listAppendData(msgList, (void*)initMsg("Music","Sean Hawk", screen));

  listAppendData(msgList, (void*)initMsg("Thx","Qubodup", screen));
  listAppendData(msgList, (void*)initMsg("Thx","Farox", screen));
  listAppendData(msgList, (void*)initMsg("Thx","bMan", screen));
  listAppendData(msgList, (void*)initMsg("Thx","KML", screen));
  listAppendData(msgList, (void*)initMsg("Thx","Neil L", screen));
  listAppendData(msgList, (void*)initMsg("Thx","Zear", screen));
  listAppendData(msgList, (void*)initMsg("Thx","ReactorScram", screen));
  listAppendData(msgList, (void*)initMsg("Thx","torpor", screen));
  listAppendData(msgList, (void*)initMsg("Thx","klopsi", screen));

  listAppendData(msgList, (void*)initMsg("Greetings","GP32X.com", screen));
  listAppendData(msgList, (void*)initMsg("Greetings","freegamedev.net", screen));
  listAppendData(msgList, (void*)initMsg("Greetings","gcw-zero.com", screen));

  //Set current
  currentMsgIndex=0;
  setCurrent();
}
Exemple #7
0
int main()
{
  int i;
  printf("Test: New list.\n");
  list_t* list = listInit(freeItem);
  listDebugShow(list,LIST_DEBUG_SHOW_BACKWARD|LIST_DEBUG_SHOW_FORWARD);
  listItem* it;

  printf("\nTest: Appending 4 items to list.\n");
  listAppendData(list, mkItem(1, "Fisk") );
  listAppendData(list, mkItem(2, "Hund") );
  it=listAppendData(list, mkItem(3, "Hest") );
  listAppendData(list, mkItem(4, "Rose") );
  listDebugShow(list,LIST_DEBUG_SHOW_SHORT);
  showItems(list);


  printf("\nTest: Prepending 4 items.\n");
  listPrependData(list, mkItem(5, "Laks") );
  listPrependData(list, mkItem(6, "Ko") );
  listPrependData(list, mkItem(7, "Tiger") );
  listPrependData(list, mkItem(8, "Zebra") );
  listDebugShow(list,LIST_DEBUG_SHOW_SHORT);
  showItems(list);


  printf("\nTest: Removing item (Hest) from list.\n");
  listRemoveItem(list,it, LIST_PREV);
  listDebugShow(list,LIST_DEBUG_SHOW_SHORT);
  showItems(list);


  printf("\nTest: Inserting 4 items\n");
  listInsertAtIdx(list, mkItem(1, "New Pos 0"), 0 );
  it=listInsertAtIdx(list, mkItem(1, "New Pos 2"), 2 );
  listInsertAtIdx(list, mkItem(1, "New Pos 8"), 8 );
  listInsertAtIdx(list, mkItem(list->count, "New Last Pos"), list->count );
  listDebugShow(list,LIST_DEBUG_SHOW_SHORT);
  showItems(list);


  printf("\nTest: Insert after item %p (New Pos 2)\n");
  listInsertAfterItem(list, it, mkItem(2, "New Pos 3") );
  listDebugShow(list,LIST_DEBUG_SHOW_SHORT);
  showItems(list);



  printf("\nTest: Getting data.\n");
  for(i=0; i < list->count; i++)
  {
    printf("  Idx %i Got data: %p\n", i, listGetItemAt(list, i )->data );
  }

  printf("\nTest: Filling list into array.\n");
  item** arr = (item**)listAddToArray( malloc(sizeof(void*)*list->count), list );

  int idx;
  for(idx=0; idx < list->count; idx++)
  {
    printf("  Arr[%i] = %p\n",idx,arr[idx] );
    showItem(arr[idx]);
  }

  printf("\nTest: Appending array to list2.\n");
  list_t* list2 = listAddFromArray(listInit(NULL), (void*)arr, list->count);
  listDebugShow(list2,LIST_DEBUG_SHOW_SHORT);
  showItems(list2);

  list_t* list3 = listAddFromArray(listInit(NULL), (void*)arr, list->count);

  free(arr);

  printf("\nRemoving all list2 elements individually in a forward loop.");
  it=&list2->begin;
  while( LISTFWD(list2,it) )
  {
    it=listRemoveItem(list2,it, LIST_PREV);
  }
  listDebugShow(list2, LIST_DEBUG_SHOW_BACKWARD|LIST_DEBUG_SHOW_FORWARD);

  printf("\nRemoving all list3 elements individually in a reverse loop.");
  it=&list3->end;
  while( LISTBCK(list3, it) )
  {
    it=listRemoveItem(list3,it,LIST_NEXT);
  }
  listDebugShow(list3, LIST_DEBUG_SHOW_BACKWARD|LIST_DEBUG_SHOW_FORWARD);



  printf("\nTest: Freeing lists.\n");
  listFree(list);
  listFree(list2);

  printf("\nTests done, it's up to you to figure out if they passed, <nelson>hahaaa!</nelson>\n");

  return(0);
}