New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add extensions to paths with a known extension already. #258

Closed
technosaurus opened this Issue Nov 30, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@technosaurus
Contributor

technosaurus commented Nov 30, 2015

Here is a replacement LoadNamedIconHelper() that does't try to add extensions to an icon with a known extension.

/** Helper for loading icons by name. */
IconNode *LoadNamedIconHelper(const char *name, const char *path,
                              char save, char preserveAspect)
{
   IconNode *result;
   char *temp;
   const unsigned nameLength = strlen(name);
   const unsigned pathLength = strlen(path);
   unsigned i, has_extension = 0;
   ImageNode *image;

   temp = AllocateStack(nameLength + pathLength + MAX_EXTENSION_LENGTH + 1);
   memcpy(&temp[0], path, pathLength);
   memcpy(&temp[pathLength], name, nameLength+1);

   result = NULL;
   size_t templen = pathLength + nameLength;
   for(i = 1; i < EXTENSION_COUNT; i++){
      if (!strcmp(ICON_EXTENSIONS[i],temp+templen-strlen(ICON_EXTENSIONS[i]))){ 
         has_extension = 1;
         break; 
      }
   }
   if (has_extension){
      image = LoadImage(temp, 0, 0, 1);
   }else for(i = 0; i < EXTENSION_COUNT; i++) {
      const unsigned len = strlen(ICON_EXTENSIONS[i]);
      memcpy(&temp[templen], ICON_EXTENSIONS[i], len + 1);
      image = LoadImage(temp, 0, 0, 1);
      if (image) break;
   }
   if (image) {
      result = CreateIcon(image);
      result->preserveAspect = preserveAspect;
      result->name = CopyString(temp);
      if (save) InsertIcon(result);
      DestroyImage(image);
   }
   ReleaseStack(temp);

   return result;
}
@joewing

This comment has been minimized.

Show comment
Hide comment
@joewing

joewing Dec 6, 2015

Owner

Fixed as of snapshot 1354.

Owner

joewing commented Dec 6, 2015

Fixed as of snapshot 1354.

@joewing joewing closed this Dec 6, 2015

@joewing joewing added this to the Versio 2.3.5 milestone Dec 6, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment