Welcome! Log In Create A New Profile

Advanced

Got network working!!! But can't do fwrite :(

Posted by SteelSLasher 
Got network working!!! But can't do fwrite :(
January 24, 2009 02:23PM
I have had a good look at WiiEarth and have been able to extract the http and dns lib from it. I have set up an app which uses the http and dns lib from wiiearth to download [www.google.com].

The good thing is that i can download the file (well i think i can) but now i want to save the contents of the variable which contains something that is from google.com into a file. I have gotten as far as

fopen("fat://google.txt", "w"); //File not created so set to w to create new file

Now how would I do fwrite? This is obviously wrong:
fwrite(file, "fat://google.txt"); //file contains the content of google.com

I found that fwrite needs a minimum of two arguments (http://www.mathworks.com/support/tech-notes/1600/1602.html]source[/url])

but how do i do fwrite with a variable of struct block:
struct block file = downloadfile("http://www.google.com/");


If anything else is needed like purpose of app or entire source then just ask!

Thx in advance (Firefox users will love you if you help, well kind of).
Re: Got network working!!! But can't do fwrite :(
January 24, 2009 05:50PM
[www.cplusplus.com]

my advise would be to (really) learn C/C++ first before attempting to play with sourcecodes

btw, the link you found is for matlab programming language: this is not going to help you in any ways for Wii programming

finally, "http://www.google.com/" is a website link, it is not a file, I really don't know what you are trying to do but I don't need your sources to tell you are thinking things wrong


I thought I had to tell you ;-)
Re: Got network working!!! But can't do fwrite :(
January 24, 2009 07:15PM
I have a http lib which can connect to the internet and DOWNLOAD data such as webpages when a function is given a url of the format
[http] [DOMAIN] PATH)


I know c to certain degree that I can make windows apps and thanks for pointing that matlab out but i am not at all familiar with "struct block" variables which is what i am stuck on. How would i get fwrite to work with "struct block" variables.



Edited 1 time(s). Last edit at 01/24/2009 07:16PM by SteelSLasher.
Re: Got network working!!! But can't do fwrite :(
January 24, 2009 07:18PM
Could you provide a small code example (preferably the declaration) of a "struct block". I think you just mean a normal struct named block, but I'm not 100% sure. With a small code example, we would be able to better help you.



Edited 1 time(s). Last edit at 01/24/2009 07:22PM by Arikado.
Re: Got network working!!! But can't do fwrite :(
January 24, 2009 08:06PM
I just found out its a memory block and made a few changes according to the function.

Heres the network init and downloader (Important bit underlined):
	printf("Wii Browse Develepment Version 1\n");
	    printf("Waiting for network to initialize...");

        s32 ip;
    while ((ip = net_init()) == -EAGAIN)
        {
                printf(".");
                usleep(100000);
        }
        printf("\n");
        
    if(ip < 0) {
                printf("Error while initialising, error is %i\n", ip);
        }
        
        char myIP[16];
    if (if_config(myIP, NULL, NULL, true) < 0) {
                printf("Error reading IP address, exiting");
                exit(0);
        }
        printf("Network initialised.\n");
        
        printf("IP: %s\n\n", myIP);
        
        printf("Let's Browse!");
        
        usleep(1000 * 1000 * 1); //1 sec
        

	printf("Attempting to download HTML file from [www.google.com]\n");
	struct block file = downloadfile("http://www.google.com/");
	printf("If domaind could not be resolved, connection ended :(\n Else the download completed successfully and youu should wait for me to do something new!\n");
	FILE * file_ptr;
	
	file_ptr = fopen("fat://google.txt", "w");
	fwrite(file.data,1,sizeof(file.data), file_ptr);

Here is the end of the downloadfile() function:
	struct block file;
	file.data = malloc(filesize);
	file.size = filesize;
	
	if(file.data == NULL)
	{
		printf("No more memory to copy file from HTTP response\n");
		free(response.data);
		return emptyblock;
	}
	
	memcpy(file.data, filestart, filesize);

	//Dispose of the original response
	free(response.data);
	
	return file;
Re: Got network working!!! But can't do fwrite :(
January 24, 2009 08:13PM
Did you call the fatInitDefault() before your file operations?
Re: Got network working!!! But can't do fwrite :(
January 25, 2009 01:59AM
fatInitDefault() after including fat.h
if you cant get files working why dont you do a printf to see if it works.
Are you sure the code works with wii networking? because that great if it does :D (compiling and having it WORK is different)
Re: Got network working!!! But can't do fwrite :(
January 25, 2009 11:12AM
the code i gave wasnt all of it, above fatinitdefault() and a few network inits are called, it seems to compile so i should have a look again today
Re: Got network working!!! But can't do fwrite :(
January 25, 2009 12:38PM
Quote

file_ptr = fopen("fat://google.txt", "w");
fwrite(file.data,1,sizeof(file.data), file_ptr);

two things:

1/ file.data is a pointer so sizeof will not return the size of the data but the size of the pointer (4 bytes). You should rather use the filesize variable from the downloadfile() function

2/ I think that with the last libfat, you can't use fat: any more as prefix for files, you have to use usb: or sd:

tbc
Re: Got network working!!! But can't do fwrite :(
January 25, 2009 01:10PM
OH GOD DAMN IT WORKS!!!

Thnx ekeeke and others for helping me with this, now onto making a html renderer or finding one made in C.
Re: Got network working!!! But can't do fwrite :(
January 25, 2009 01:16PM
SteelSLasher: whats the app for? depending what you need you can do things in a very simple or very complex way.

html render? are you trying to write a browser? what do you need the 'html render' to do? i hope its just text and displaying jpgs + simple alignment (no br == fail)
Re: Got network working!!! But can't do fwrite :(
January 25, 2009 05:20PM
Quote
mavakadachi
SteelSLasher: whats the app for? depending what you need you can do things in a very simple or very complex way.

html render? are you trying to write a browser? what do you need the 'html render' to do? i hope its just text and displaying jpgs + simple alignment (no br == fail)

That's right! I am going to start with simple one column rendering then eventually add stuff to it.

If you could recommend any methods which would be simple I would be grateful, I mean not having many of the php string functions natively in C really kicks you in the teeth when you try to EXPLODE! or IMPLODE! .

I was thinking that i start a loop that goes through each character of the webpage and each < it meets it will expect a word after it then a space and then... It shouldn't cause too many lazy code problems but I dont want to use regex

I have a javascript renderer for wii (SpiderMonkey in C) but no renderers were coded in C (that i know of) so homemade it is then
Re: Got network working!!! But can't do fwrite :(
January 26, 2009 02:16AM
If you're trying to write a web browser then I'd suggest taking a look at the source for firefox or dooble. You may get some ideas for writing your parser. Or I found this the other day - [code.peterstuifzand.nl]

Would be nice to have a free browser for the Wii but after looking it would be a lot of work and really thinking about it even with an on screen keyboard it would be easier for me just to open up my laptop an browse.
Re: Got network working!!! But can't do fwrite :(
January 26, 2009 02:47AM
Why do you want to write this?
p0rN 4 your WII? (lolz)

I cant see youtube working with this.
If you can get webpages i have an idea how to play youtube videos but last time i tried to compile mplayer i got errors (i didnt have the correct patches, this wasnt the current DKP)
Re: Got network working!!! But can't do fwrite :(
January 26, 2009 12:11PM
Nice joke! I was thinking fo creating a system where different rules are set for certain websites, for YouTube I would extract the video from the url and display that using something (not sure yet).

There is also a GNU of Flash which may be good

BTW this is just an intermediate for creating some other game based tools (achievements, anti-FC etc.)



Edited 2 time(s). Last edit at 01/26/2009 12:34PM by SteelSLasher.
Re: Got network working!!! But can't do fwrite :(
January 28, 2009 05:33AM
This sounds like an interesting project. I would be interested to see the development of this project progress. It would be cool to have a Firefox equivalent for the Wii simply because I prefer Firefox to other browsers competing browsers. I wish you the best of luck.
Re: Got network working!!! But can't do fwrite :(
January 30, 2009 07:45PM
Thanks, right now i have two choices: port antlr or use a C++ wrapper with Boost Spirit
Re: Got network working!!! But can't do fwrite :(
January 31, 2009 08:10AM
port antlr !?! dont you generate c(++) code with antlr and just use it in your project?
Why do you need to use these? i thought you only needed to DL the html page+images and do a simple render on screen?
Re: Got network working!!! But can't do fwrite :(
January 31, 2009 02:57PM
Quote
mavakadachi
port antlr !?! dont you generate c(++) code with antlr and just use it in your project?
Why do you need to use these? i thought you only needed to DL the html page+images and do a simple render on screen?

Really? I should look that up since ANTLR has no support for C++ and i thought it was a library?
Re: Got network working!!! But can't do fwrite :(
February 02, 2009 02:21PM
Quote
SteelSLasher
Quote
mavakadachi
port antlr !?! dont you generate c(++) code with antlr and just use it in your project?
Why do you need to use these? i thought you only needed to DL the html page+images and do a simple render on screen?

Really? I should look that up since ANTLR has no support for C++ and i thought it was a library?

NOTE: I havent done anything with it. From what i can tell its HARD to get it generating code for c++ and i couldnt get anything working with it. I havent tried hard tho.

Why are you going to port antlr again? theres no reason to generate a parser for a custom script?
Sorry, only registered users may post in this forum.

Click here to login