fn save_gophermap(&mut self, filename: String) {
        let content: String;
        {
            let guard = self.content.lock().unwrap();
            content = guard.clone();
        }
        let tx_clone = self.tx.read().unwrap().clone();
        let lines = content.lines();
        let mut txtlines = Vec::<String>::new();
        let mut first = true;
        for l in lines {
            if first {
                first = false;
                continue;
            }
            if l != "." {
                match GopherMapEntry::parse(l.to_string()) {
                    Ok(gl) => txtlines.push(gl.label().to_string()),
                    Err(err) => {
                        warn!("Invalid gophermap line: {}", err);
                    }
                };
            }
        }
        info!("Save textfile: {}", filename);
        // Create a path to the desired file
        let mut download_path = String::new();
        if let Ok(path) = SETTINGS.read().unwrap().get_str("download_path") {
            download_path = path.to_string();
        }
        let path = Path::new(download_path.as_str()).join(filename.as_str());
        let display = path.display();

        let mut file = match File::create(&path) {
            Err(err) => {
                tx_clone
                    .send(ControllerMessage::ShowMessage(format!(
                        "Could open: {}: {}",
                        display, err
                    )))
                    .unwrap();
                return;
            }
            Ok(file) => file,
        };

        // Read the file contents into a string, returns `io::Result<usize>`
        for l in txtlines {
            if let Err(err) = file.write_all(format!("{}\n", l).as_bytes()) {
                tx_clone
                    .send(ControllerMessage::ShowMessage(format!(
                        "Could not write: {}: {}",
                        display, err
                    )))
                    .unwrap();
                return;
            }
        }
        // `file` goes out of scope and the file gets closed
    }
/// Save the current gophermap to disk
Save the current gophermap to disk
Save the current gophermap to disk
fn save_gophermap(&mut self, filename: String) {
        let content: String;
        {
            let guard = self.content.lock().unwrap();
            content = guard.clone();
        }
        let tx_clone = self.tx.read().unwrap().clone();
        let lines = content.lines();
        let mut txtlines = Vec::<String>::new();
        let mut first = true;
        for l in lines {
            if first {
                first = false;
                continue;
            }
            if l != "." {
                match GopherMapEntry::parse(l.to_string()) {
                    Ok(gl) => txtlines.push(gl.label().to_string()),
                    Err(err) => {
                        warn!("Invalid gophermap line: {}", err);
                    }
                };
            }
        }
        info!("Save textfile: {}", filename);
        // Create a path to the desired file
        let mut download_path = String::new();
        if let Ok(path) = SETTINGS.read().unwrap().get_str("download_path") {
            download_path = path.to_string();
        }
        let path = Path::new(download_path.as_str()).join(filename.as_str());
        let display = path.display();
        let mut file = match File::create(&path) {
            Err(err) => {
                tx_clone
                    .send(ControllerMessage::ShowMessage(format!(
                        "Could open: {}: {}",
                        display, err
                    )))
                    .unwrap();
                return;
            }
            Ok(file) => file,
        };
        // Read the file contents into a string, returns `io::Result<usize>`
        for l in txtlines {
            if let Err(err) = file.write_all(format!("{}\n", l).as_bytes()) {
                tx_clone
                    .send(ControllerMessage::ShowMessage(format!(
                        "Could not write: {}: {}",
                        display, err
                    )))
                    .unwrap();
                return;
            }
        }
        // `file` goes out of scope and the file gets closed
    }
fn save_gophermap ( & mut self , filename : String ) { let content : String ; { let guard = self . content . lock ( ) . unwrap ( ) ; content = guard . clone ( ) ; } let tx_clone = self . tx . read ( ) . unwrap ( ) . clone ( ) ; let lines = content . lines ( ) ; let mut txtlines = Vec :: < String > :: new ( ) ; let mut first = true ; for l in lines { if first { first = false ; continue ; } if l != " " { match GopherMapEntry :: parse ( l . to_string ( ) ) { Ok ( gl ) => txtlines . push ( gl . label ( ) . to_string ( ) ) , Err ( err ) => { warn ! ( " " err ) ; } } ; } } info ! ( " " filename ) ; // Create a path to the desired file let mut download_path = String :: new ( ) ; if let Ok ( path ) = SETTINGS . read ( ) . unwrap ( ) . get_str ( " " ) { download_path = path . to_string ( ) ; } let path = Path :: new ( download_path . as_str ( ) ) . join ( filename . as_str ( ) ) ; let display = path . display ( ) ; let mut file = match File :: create ( & path ) { Err ( err ) => { tx_clone . send ( ControllerMessage :: ShowMessage ( format ! ( " " display err ) ) ) . unwrap ( ) ; return ; } Ok ( file ) => file , } ; // Read the file contents into a string, returns `io::Result<usize>` for l in txtlines { if let Err ( err ) = file . write_all ( format ! ( " \n " l ) . as_bytes ( ) ) { tx_clone . send ( ControllerMessage :: ShowMessage ( format ! ( " " display err ) ) ) . unwrap ( ) ; return ; } } // `file` goes out of scope and the file gets closed }
Save the current gophermap to disk
Save the current gophermap to disk
&mut self
filename
String
&mut self
filename
String