/* --- OP_WINAMP.CPP --- / / Written by Phil Himsworth, 2001-2002. / /*/ #include #include "types.h" #include "main.h" #include "plugin.h" #include "html.h" #include "wamessage.h" #include "op_winamp.h" #include "resource.h" extern char mp3root[MAX_PATH], playlistdir[MAX_PATH], logfiledir[MAX_PATH], filetypes[255]; extern int browse_enable, dl_wa_files, dl_other_files, show_other_files, frames, title_refresh, securepassword; extern char szAppVer[]; extern char pagetitle[255]; extern winampGeneralPurposePlugin plugin; // -------------------------------------------------------------------------------- // Send an image from a resource int CControl::Image(connection * conn,int type) { //char * img = &conn->http.file[5]; char img[30]; GetArgValue(conn,"image",(char*)&img,30); //MessageBox(NULL,img,"gen_httpSrv debug",MB_OK | MB_TOPMOST); int imageid = atoi2(img); char dll[MAX_PATH]; GetModuleFileName(plugin.hDllInstance,dll,sizeof(dll)); HMODULE hm = GetModuleHandle(dll); if (hm == NULL) MessageBox(NULL,"gmh failed","gen_httpSrv debug",MB_OK); HRSRC resimage = FindResource(hm,MAKEINTRESOURCE(imageid),"Image"); if (!resimage) // after an image that doesn't exist { //MessageBox(NULL,"Bad image","gen_httpSrv debug",MB_OK); return ST_CLOSE; //closesocket(conn.socket); //return true; } HGLOBAL image = LoadResource(hm, resimage); DWORD imglen = SizeofResource(hm, resimage); switch(type) { case IMG_GIF: OpenHTTPHeader(conn,"image/gif",(int)imglen,NULL); break; case IMG_ICO: OpenHTTPHeader(conn,"image/x-icon",(int)imglen,NULL); break; } if(conn->http.reqID == RID_HEAD) return ST_CLOSE; flush(conn); send(conn->socket,(char*)image,imglen,0); return ST_CLOSE; } // -------------------------------------------------------------------------------- // Sends top frame with buttons and the like int CControl::TopFrame(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); CloseHeader(conn); OpenHeaderBody(conn); LinkTable(conn); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Tiny title int CControl::SmallTitle(connection * conn) { conn->log = false; OpenHTTPHeader(conn,"text/plain",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; SongInfo(conn); prints(conn,"\n\n"); return ST_CLOSE; } // -------------------------------------------------------------------------------- // Sends full title information int CControl::Title(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; else { OpenHtmlHeader(conn); prints(conn,"\n"); Style(conn); CloseHeader(conn); OpenPageBody(conn); FullSongInfo(conn); prints(conn,"\n"); return ST_CLOSEBODY; } } // -------------------------------------------------------------------------------- // Shuts down winamp and the computer, in theory. Doesn't, though... int CControl::Shutdown(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

Turning off...

\n"); ExitWindows(0,0); PostMessage(WAwnd(),WM_CLOSE,0,0); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Clears playlist int CControl::Clear(connection * conn) { SendMessage(WAwnd(),WM_USER,0,WAU_CLEARPLIST); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); RefreshHeader(conn,"/list"); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

Playlist cleared

\n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Download a song int CControl::Download(connection * conn) { // exactly the same filename processing as Load, below. char filepath[MAX_PATH]; GetArgValue(conn,"file",filepath,MAX_PATH); //char *relfilepath = &conn->http.file[4]; Unescape_url(filepath); ReplaceSlashes(filepath); if (!GoodPath(filepath)) ReportError(conn,"

The path requested is illegal.

\n

It cotains the .. directory, which could present a security risk.

\n"); else { bool wafile = IsWinampFile(GetFilename(filepath)); if ((wafile && dl_wa_files==0) || (!wafile && dl_other_files==0)) ReportError(conn,"

Downloading files of this type is not permitted from this server.

"); else { char fullfilepath[MAX_PATH]; int pathlen = wsprintf(fullfilepath,"%s%s",mp3root,filepath); Unescape_url((char*)&fullfilepath); /* - Open a header with the right MIME type - needs file size - Call TransmitFile() - Rockin'. */ HANDLE hFile = CreateFile( fullfilepath, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, 0); if (hFile == INVALID_HANDLE_VALUE) ReportError(conn,"

Couldn't open the file.

\n

Check the file exists and the name is correct.

\n"); else { DWORD dwSize = GetFileSize(hFile, NULL); OpenHTTPHeader(conn,"audio/mpeg",dwSize,GetFilename(fullfilepath)); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; flush(conn); TransmitFile(conn->socket, hFile, dwSize, 0, NULL, NULL, NULL); CloseHandle(hFile); return ST_CLOSE; } } } return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Load a song into the playlist int CControl::Load(connection * conn) { char relfilepath[MAX_PATH]; char filepath[MAX_PATH]; char shortcutfilepath[MAX_PATH]; char playmode[10]; GetArgValue(conn,"path",relfilepath,MAX_PATH); Unescape_url(relfilepath); char refreshto[MAX_PATH]; if (relfilepath[0] == '\\' && relfilepath[1] != '\\') // single slash - local file (not UNC '\\' or HTTP 'http://...') { if (!GoodPath(relfilepath)) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

Error! The path requested is illegal.

\n"); prints(conn,"

 

\n"); return ST_CLOSEBODY; } else // Local path is okay { // need to check whether it's a url shortcut file fileinfo file; lstrcpy(file.name,relfilepath); IsWinampFile(&file); if (file.urlsct) // url shortcut; load contained address into 'filepath' { wsprintf(shortcutfilepath,"%s%s",mp3root,relfilepath); GetPrivateProfileString("InternetShortcut","URL","",filepath,MAX_PATH,shortcutfilepath); } else // not a shortcut; just put the right path into filepath { wsprintf(filepath,"%s%s",mp3root,relfilepath); } // refresh to "/browse?path=" char * p; if (frames == 3) wsprintf(refreshto,"/title"); else { char refreshtemp[MAX_PATH]; wsprintf(refreshtemp,"%s",relfilepath); p=refreshtemp+lstrlen(refreshtemp); while (p >= refreshtemp && *p != '\\') p--; if (++p >= refreshtemp) *p = 0; Escape_url(refreshtemp); wsprintf(refreshto,"/browse?path=%s",refreshtemp); } } } else // HTTP or UNC name; load directly { wsprintf(filepath,"%s",relfilepath); } //MessageBox(NULL,filepath,"filepath",MB_OK | MB_TOPMOST); int pathlen = lstrlen(filepath); COPYDATASTRUCT cds; cds.dwData = IPC_PLAYFILE; cds.lpData = (void *)&filepath; cds.cbData = pathlen+1; SendMessage(WAwnd(),WM_COPYDATA,(WPARAM)NULL,(LPARAM)&cds); if (GetArgValue(conn,"play",playmode,10)) { if (StrComp(playmode,"now")) { int pl_len = SendMessage(WAwnd(),WM_USER,0,WAU_PLCOUNT); SendMessage(WAwnd(),WM_USER,pl_len-1,WAU_SETPLPOS); SendMessage(WAwnd(),WM_COMMAND,WAC_PLAY,0); } } OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; GetArgValue(conn,"refresh",refreshto,10); // will overwrite existing value if // the param exists OpenHtmlHeader(conn); Style(conn); RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

Load file command sent:   "); prints(conn,relfilepath); // actually relfilepath prints(conn,"

\n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Send playlist page int CControl::List(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); CloseHeader(conn); OpenPageBody(conn); if (frames == 1) LinkBar(conn); prints(conn,"

\n\n... Current Playlist ...\n

\n"); prints(conn,"
\n"); prints(conn,"Show only songs containing: \n"); prints(conn,"\n"); prints(conn,"
\n"); prints(conn,"
\nJump to Current Track | "); prints(conn,"Sort Playlist | Clear Playlist"); prints(conn," | Save Playlist
\n
    \n"); char song[255], lcasesong[255], substring[255]; bool restrict = GetArgValue(conn,"sub",substring,255); // search for substring? if (restrict && substring[0] == 0) // if it's blank, show all restrict = false; if (restrict) { Unescape_url(substring); CharLower(substring); prints(conn,"

    Showing songs containing: "); prints(conn,substring); prints(conn,"

    \n"); } prints(conn,"
      \n"); int current = SendMessage(WAwnd(),WM_USER, 0, WAU_GETPLPOS); char tbuffer[255]; int t = SendMessage(WAwnd(),WM_USER, 0, WAU_PLCOUNT); for (int count=0;count"); prints(conn,"
    1. "); wsprintf(tbuffer,"/delete?track=%d",count+1); ImgLink(conn,tbuffer,IDR_IMG_LIST_DEL,"Remove",0,0,T_MAIN); wsprintf(tbuffer,"/play?track=%d",count+1); ImgLink(conn,tbuffer,IDR_IMG_LIST_PLAY,"Play",0,0,T_BOTTOM); if (frames == 3) wsprintf(tbuffer,"%s
    2. \n", count+1, song); else wsprintf(tbuffer,"%s\n", count+1, song); prints(conn,tbuffer); if (count == current) prints(conn,""); } } prints(conn,"
    \n

    "); if (frames == 1) LinkBar(conn); prints(conn,"

     

    "); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Next track int CControl::Next(connection * conn) { SendMessage(WAwnd(),WM_COMMAND,WAC_NEXT,0); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) { if (frames == 3) wsprintf(refreshto,"/title"); else wsprintf(refreshto,"/main"); } RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Next track command sent

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Previous track int CControl::Prev(connection * conn) { SendMessage(WAwnd(),WM_COMMAND,WAC_PREV,0); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) { if (frames == 3) wsprintf(refreshto,"/title"); else wsprintf(refreshto,"/main"); } RefreshHeader(conn,refreshto); Style(conn); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Previous track command sent

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Start playback int CControl::Play(connection * conn) { char strtrack[10]; if (GetArgValue(conn,"track",strtrack,10)) { int track = atoi2(strtrack) - 1; if (track >= 0) SendMessage(WAwnd(),WM_USER,track,WAU_SETPLPOS); } SendMessage(WAwnd(),WM_COMMAND,WAC_PLAY,0); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) { if (frames == 3) wsprintf(refreshto,"/title"); else wsprintf(refreshto,"/main"); } RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Play command sent

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Stop playback int CControl::Stop(connection * conn) { SendMessage(WAwnd(),WM_COMMAND,WAC_STOP,0); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) { if (frames == 3) wsprintf(refreshto,"/title"); else wsprintf(refreshto,"/main"); } RefreshHeader(conn,refreshto); Style(conn); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Stop command sent

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Stop with fadeout int CControl::StopSlow(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) { if (frames == 3) wsprintf(refreshto,"/title"); else wsprintf(refreshto,"/main"); } RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Stopping..."); flush(conn); SendMessage(WAwnd(),WM_COMMAND,WAC_STOPFADE,0); prints(conn," OK!

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Pause. Why am I even bothering to comment these?!? int CControl::Pause(connection * conn) { SendMessage(WAwnd(),WM_COMMAND,WAC_PAUSE,0); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) { if (frames == 3) wsprintf(refreshto,"/title"); else wsprintf(refreshto,"/main"); } RefreshHeader(conn,refreshto); Style(conn); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Pause command sent

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Change volume int CControl::Volume(connection * conn) { char strvol[20]; GetArgValue(conn,"volume",strvol,20); int vol = atoi2(strvol); // Mwuahaha, die Clib vol = (int)(vol * 25.5); SendMessage(WAwnd(),WM_USER,vol,122); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) { if (frames == 3) wsprintf(refreshto,"/title"); else wsprintf(refreshto,"/main"); } RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Change volume command sent

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Change repeat / random modes int CControl::Playmode(connection * conn) { char repeat[10], random[10]; if (!GetArgValue(conn,"repeat",repeat,10)) wsprintf(repeat,"none"); if (!GetArgValue(conn,"random",random,10)) wsprintf(random,"none"); OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) wsprintf(refreshto,"/main"); RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); if (StrComp(repeat,"on")) { SendMessage(WAwnd(),WM_USER,1,WAU_SETREPEAT); prints(conn,"

    Repeat set to ON

    "); } if (StrComp(repeat,"off")) { SendMessage(WAwnd(),WM_USER,0,WAU_SETREPEAT); prints(conn,"

    Repeat set to OFF

    "); } if (StrComp(repeat,"toggle")) { SendMessage(WAwnd(),WM_COMMAND,WAC_REPEATT,0); prints(conn,"

    Repeat toggled

    "); } if (StrComp(random,"on")) { SendMessage(WAwnd(),WM_USER,1,WAU_SETRANDOM); prints(conn,"

    Random set to ON

    "); } if (StrComp(random,"off")) { SendMessage(WAwnd(),WM_USER,0,WAU_SETRANDOM); prints(conn,"

    Random set to OFF

    "); } if (StrComp(random,"toggle")) { SendMessage(WAwnd(),WM_COMMAND,WAC_RANDOMT,0); prints(conn,"

    Random toggled

    "); } return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // About box int CControl::About(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); CloseHeader(conn); prints(conn,"\n"); prints(conn,"

    Winamp Web Interface
    \nVersion "); prints(conn,szAppVer); prints(conn,"

    \n"); prints(conn,"

    \n\nPhil Himsworth 2002
    \n"); prints(conn,"contact@flippet.net · www.flippet.net\n
    \n

    \n\n"); prints(conn,"\n"); flush(conn); closesocket(conn->socket); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Main window int CControl::Main(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    \n\n"); prints(conn,pagetitle); prints(conn,"\n\n\n

    \n"); prints(conn,"
    \nAbout Winamp Web Interface v."); prints(conn,szAppVer); prints(conn,"
    "); prints(conn,"
    \n"); prints(conn,"

    \n\n... Winamp Status ...\n

    \n"); prints(conn,"

    \n"); FullSongInfo(conn); prints(conn,"

    \n"); int repeat = SendMessage(WAwnd(),WM_USER,0,WAU_GETREPEAT); int random = SendMessage(WAwnd(),WM_USER,0,WAU_GETRANDOM); prints(conn,"

    Repeat is "); if (repeat == 1) prints(conn,"on "); if (repeat == 0) prints(conn,"off "); prints(conn,"[ "); Link(conn,"/playmode?repeat=on","on",T_NONE); prints(conn," | "); Link(conn,"/playmode?repeat=off","off",T_NONE); prints(conn," | "); Link(conn,"/playmode?repeat=toggle","toggle",T_NONE); prints(conn," ]"); prints(conn,"
    Random is "); if (random == 1) prints(conn,"on "); if (random == 0) prints(conn,"off "); prints(conn,"[ "); Link(conn,"/playmode?random=on","on",T_NONE); prints(conn," | "); Link(conn,"/playmode?random=off","off",T_NONE); prints(conn," | "); Link(conn,"/playmode?random=toggle","toggle",T_NONE); prints(conn," ]"); prints(conn,"

    \n"); if (frames == 1) LinkBar(conn); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // PDA mode - small int CControl::pda(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); CloseHeader(conn); prints(conn,"\n"); prints(conn,"

    \n"); ImgLink(conn,"/prev?refresh=pda",IDR_IMG_PREV,"Previous Track",0,0,T_NONE); Img(conn,IDR_IMG_BLACK,"",2,30); ImgLink(conn,"/play?refresh=pda",IDR_IMG_PLAY,"Play",0,0,T_NONE); Img(conn,IDR_IMG_BLACK,"",2,30); ImgLink(conn,"/pause?refresh=pda",IDR_IMG_PAUSE,"Pause",0,0,T_NONE); Img(conn,IDR_IMG_BLACK,"",2,30); ImgLink(conn,"/stop?refresh=pda",IDR_IMG_STOP,"Stop",0,0,T_NONE); Img(conn,IDR_IMG_BLACK,"",2,30); ImgLink(conn,"/next?refresh=pda",IDR_IMG_NEXT,"Next Track",0,0,T_NONE); prints(conn,"

    \n

    \n"); // Volume control links ImgLink(conn,"/vol?volume=0&refresh=pda",IDR_VOL_00,"0/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=1&refresh=pda",IDR_VOL_01,"1/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=2&refresh=pda",IDR_VOL_02,"2/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=3&refresh=pda",IDR_VOL_03,"3/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=4&refresh=pda",IDR_VOL_04,"4/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=5&refresh=pda",IDR_VOL_05,"5/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=6&refresh=pda",IDR_VOL_06,"6/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=7&refresh=pda",IDR_VOL_07,"7/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=8&refresh=pda",IDR_VOL_08,"8/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=9&refresh=pda",IDR_VOL_09,"9/10",0,0,T_NONE); ImgLink(conn,"/vol?volume=10&refresh=pda",IDR_VOL_10,"10/10",0,0,T_NONE); prints(conn,"\n

    \n

    \n"); int repeat = SendMessage(WAwnd(),WM_USER,0,WAU_GETREPEAT); int random = SendMessage(WAwnd(),WM_USER,0,WAU_GETRANDOM); if (repeat) ImgLink(conn,"/playmode?repeat=toggle&refresh=pda",IDR_IMG_RPT_ON,"Toggle Repeat",0,0,T_NONE); else ImgLink(conn,"/playmode?repeat=toggle&refresh=pda",IDR_IMG_RPT_OFF,"Toggle Repeat",0,0,T_NONE); if (random) ImgLink(conn,"/playmode?random=toggle&refresh=pda",IDR_IMG_RND_ON,"Toggle Random",0,0,T_NONE); else ImgLink(conn,"/playmode?random=toggle&refresh=pda",IDR_IMG_RND_OFF,"Toggle Random",0,0,T_NONE); prints(conn,"

    \n"); return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Delete playlist entry. Uses DeletePlaylistEntry2() int CControl::Delete(connection * conn) // using Playlist Window message { char strtrack[20]; GetArgValue(conn,"track",strtrack,20); int track = atoi2(strtrack); return DeletePlaylistEntry2(conn,track-1); } // -------------------------------------------------------------------------------- // Returns wawi.css int CControl::UserStyle(connection * conn) { OpenHTTPHeader(conn,"text/plain",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; char style_file[MAX_PATH], *p; GetModuleFileName(plugin.hDllInstance,style_file,sizeof(style_file)); p=style_file+lstrlen(style_file); while (p >= style_file && *p != '\\') p--; if (++p >= style_file) *p = 0; lstrcat(style_file,"wawi.css"); HANDLE hFile = CreateFile( style_file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (hFile == INVALID_HANDLE_VALUE) { prints(conn,"BODY\n{\nFONT-FAMILY: arial,sans-serif\n}\nA:link\n{\nCOLOR: blue;\nTEXT-DECORATION: none\n}\nA:visited\n{\nCOLOR: blue;\nTEXT-DECORATION: none\n}\nA:active\n{\nCOLOR: #ff9050;\nTEXT-DECORATION: none\n}\nA:hover\n{\nCOLOR: #e4a029;\nTEXT-DECORATION: none\n}\n\n"); return ST_CLOSE; } DWORD dwSize = GetFileSize(hFile, NULL); flush(conn); TransmitFile(conn->socket, hFile, dwSize, 0, NULL, NULL, NULL); CloseHandle(hFile); prints(conn,"\n\n"); return ST_CLOSE; } // -------------------------------------------------------------------------------- // Sorts playlist int CControl::Sort(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) wsprintf(refreshto,"/list"); RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Sorting..."); flush(conn); HWND playlistwnd = FindWindow("Winamp PE","Winamp Playlist Editor"); if (playlistwnd == NULL) prints(conn,"Error: Couldn't find Winamp Playlist window...

    "); else { SendMessage(playlistwnd,WM_COMMAND,PLC_SORTTITLE,0); prints(conn," OK!

    \n"); } return ST_CLOSEBODY; } // -------------------------------------------------------------------------------- // Saves playlist int CControl::SavePlaylist(connection * conn) { OpenHTTPHeader(conn,"text/html",0,NULL); if (conn->http.reqID == RID_HEAD) return ST_CLOSE; OpenHtmlHeader(conn); Style(conn); char location[MAX_PATH]; char nicelocation[MAX_PATH]; char fulllocation[MAX_PATH]; // see if a location is specified; ask if not if (!GetArgValue(conn,"location",location,MAX_PATH)) { // no location; pop up form CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    ... Save Playlist ...

    \n"); prints(conn,"
    \n"); prints(conn,"

    Playlist Name: \n"); prints(conn,"

    \n"); prints(conn,"
    \n"); prints(conn,"

     

    \n"); Link(conn,"/list","Return to Playlist",T_NONE); } else { char refreshto[MAX_PATH]; if (!GetArgValue(conn,"refresh",refreshto,10)) wsprintf(refreshto,"/list"); // location given; save it to mp3root \ playlist directory \ location int dirlen = strlen(playlistdir); if (dirlen == 0) wsprintf(nicelocation,"%s.m3u",location); else wsprintf(nicelocation,"%s\\%s.m3u",playlistdir,location); wsprintf(fulllocation,"%s\\%s",mp3root,nicelocation); //MessageBox(NULL,fulllocation,nicelocation,MB_OK | MB_TOPMOST); SendMessage(WAwnd(),WM_USER,0,WAU_PLSAVE); // Find winamp.m3u; it's in the same dir as exe of current process. DWORD wapid = GetWindowThreadProcessId(WAwnd(),NULL); HMODULE hMod = (HMODULE)OpenProcess(PROCESS_ALL_ACCESS,false,wapid); char playlistfile[MAX_PATH], *p; GetModuleFileName(hMod,playlistfile,sizeof(playlistfile)); CloseHandle(hMod); // Make \path\winamp.exe into \path\winamp.m3u p=playlistfile+lstrlen(playlistfile); while (p >= playlistfile && *p != '\\') p--; if (++p >= playlistfile) *p = 0; lstrcat(playlistfile,"winamp.m3u"); if (CopyFile(playlistfile,fulllocation,true) == 0) { // function failed; try again if (CopyFile(playlistfile,fulllocation,false) == 0) { // failed totally; tell them CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Error!

    Couldn't save the playlist to "); prints(conn,nicelocation); prints(conn,"

    \n

    Does the directory exist?

    "); Link(conn,"list","Back to Playlist",T_NONE); } else { // file overwritten RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Playlist saved to "); prints(conn,nicelocation); prints(conn,"\n

    Previous playlist overwritten.

    \n"); } } else { // file copied ok RefreshHeader(conn,refreshto); CloseHeader(conn); OpenPageBody(conn); prints(conn,"

    Playlist saved to "); prints(conn,nicelocation); prints(conn,"

    \n"); } } if (frames == 1) LinkBar(conn); return ST_CLOSEBODY; }