[go: up one dir, main page]

Menu

[r22]: / in_vgm / trunk / common.c  Maximize  Restore  History

Download this file

146 lines (128 with data), 5.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <string.h> // strstr
#include <stdio.h> // sprintf
#include <math.h> // log
#include <windows.h> // HWND
#include <commctrl.h> // TBM_*
#include <zlib.h> // zlib stuff
#include "common.h"
#include "vgm.h" // VGM header
#include "gd3.h" // GD3 header
#include "wa_ipc.h" // Winamp messages
//-----------------------------------------------------------------
// Check if string is a URL
//-----------------------------------------------------------------
int IsURL(char *url) {
if (
(strstr(url,"http://")==url) ||
(strstr(url,"ftp://" )==url) ||
(strstr(url,"www." )==url)
) return 1;
return 0;
}
//-----------------------------------------------------------------
// Convert a time in seconds to a nice format
//-----------------------------------------------------------------
char* PrintTime(char *s,double timeinseconds) {
// Convert to the various timescales
double secs=timeinseconds;
int mins =(int)timeinseconds / 60;
int hours =(int)timeinseconds / ( 60 * 60 );
int days =(int)timeinseconds / ( 60 * 60 * 24 );
// Subtract the next largest's part tp get the remainder (in smallest to largest order)
secs -= mins * 60;
mins -= hours * 60;
hours -= days * 24;
if(days)
// very unlikely
sprintf(s,"%dd+%d:%02d:%04.1f",days,hours,mins,secs);
else if(hours)
// unlikely
sprintf(s,"%d:%02d:%04.1f",hours,mins,secs);
else if(mins)
sprintf(s,"%d:%04.1f",mins,secs);
else
sprintf(s,"%.1fs",secs);
return s;
}
//-----------------------------------------------------------------
// Setup a trackbar control
//-----------------------------------------------------------------
void SetupSlider(HWND hDlg, int nDlgItem, int min, int max, int ticfreq, int position) {
SendDlgItemMessage(hDlg,nDlgItem,TBM_SETRANGE,0,MAKELONG(min,max));
SendDlgItemMessage(hDlg,nDlgItem,TBM_SETTICFREQ,ticfreq,0);
SendDlgItemMessage(hDlg,nDlgItem,TBM_SETPOS,TRUE,position);
}
//-----------------------------------------------------------------
// Read and check a TVGMHeader
//-----------------------------------------------------------------
struct TVGMHeader *ReadVGMHeader( gzFile *fh, BOOL needsGD3 )
{
int i;
struct TVGMHeader *VGMHeader = malloc(sizeof(struct TVGMHeader));
if ( !VGMHeader )
return NULL; // failed to allocate it
i=gzread(fh,VGMHeader,sizeof(struct TVGMHeader));
if (
( i < sizeof(struct TVGMHeader) ) || // file too short/error reading
( VGMHeader->VGMIdent != VGMIDENT ) || // no marker
( VGMHeader->Version < MINVERSION ) || // below min ver
( (VGMHeader->Version & REQUIREDMAJORVER) != REQUIREDMAJORVER ) || // != required major ver
( needsGD3 && !VGMHeader->GD3Offset ) // no GD3
) {
free(VGMHeader);
return NULL;
}
return VGMHeader;
}
//-----------------------------------------------------------------
// Read and check a TGD3Header
//-----------------------------------------------------------------
struct TGD3Header *ReadGD3Header( gzFile *fh )
{
int i;
struct TGD3Header *GD3Header = malloc(sizeof(struct TGD3Header));
if ( !GD3Header )
return NULL; // failed to allocate it
i=gzread(fh,GD3Header,sizeof(struct TGD3Header));
if (
( i < sizeof(struct TGD3Header) ) || // file too short/error reading
( GD3Header->GD3Ident != GD3IDENT ) || // no marker
( GD3Header->Version < MINGD3VERSION) || // below min ver
( ( GD3Header->Version & REQUIREDGD3MAJORVER ) != REQUIREDGD3MAJORVER ) // != required major ver
) {
free(GD3Header);
return NULL;
}
return GD3Header;
}
//-----------------------------------------------------------------
// Open URL in minibrowser or browser
//-----------------------------------------------------------------
void OpenURL(HWND winamp_wnd, char *url, char *TempHTMLFile, int UseMB) {
FILE *f;
f=fopen(TempHTMLFile,"wb");
// Put start text
fprintf(f,
"<html><head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=%s\"></head><body>Opening %s<br><a href=\"%s\">Click here if page does not open</a></body></html>",
url,url,url
);
fclose(f);
if (UseMB) {
url=malloc(strlen(TempHTMLFile)+9);
strcpy(url,"file:///");
strcat(url,TempHTMLFile);
SendMessage(winamp_wnd,WM_USER,(WPARAM)NULL, IPC_MBOPEN); // open minibrowser
SendMessage(winamp_wnd,WM_USER,(WPARAM)url, IPC_MBOPEN); // display file
free(url);
}
else ShellExecute(winamp_wnd,NULL,TempHTMLFile,NULL,NULL,SW_SHOWNORMAL);
}
int FileSize(char *filename)
{
int filesize;
HANDLE fh = CreateFile( filename, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if (!fh) return 0;
filesize = GetFileSize( fh, NULL );
CloseHandle( fh );
return filesize;
}